Skip to content

Instantly share code, notes, and snippets.

View mujahidi's full-sized avatar

Mujahid Ishtiaq mujahidi

  • Pakistan
View GitHub Profile
@mujahidi
mujahidi / script.js
Created November 17, 2025 19:48
Make sidebar sticky using JS
const sidebar = document.querySelector('.sidebar-is-sticky');
const content = document.getElementById('main');
const footer = document.querySelector('.site-footer');
if (sidebar && content && footer) {
let sidebarTop = null;
let ticking = false;
// Only recalc sidebarTop on load/resize, not on every scroll (prevents flicker)
function recalcSidebarTop() {
@mujahidi
mujahidi / README.md
Last active November 5, 2025 14:55
Local Development with Automated Remote Server Sync - Complete Setup

Complete setup for local web development with automated file synchronization to remote server. This configuration allows you to:

  • Develop locally with full IDE features and build tools
  • Compile SCSS/JS assets locally
  • Sync all changes (source files + compiled assets) to remote server via SSH
  • No need for FTP/SFTP - works with SSH-only access
  • Perfect for staging/live servers where you can't install Node.js

Features:

  • File watcher that syncs changes in real-time
@mujahidi
mujahidi / main.js
Last active November 3, 2025 16:10
Add sticky sidebar behavior using vanilla javascript to keep the sidebar visible while scrolling, and prevent it from overlapping the footer.
// Make sidebar sticky
const sidebar = document.querySelector('.sidebar-form');
const content = document.getElementById('main');
const footer = document.querySelector('.site-footer');
if (sidebar && content && footer) {
let sidebarTop = null;
function recalcSidebarTop() {
@mujahidi
mujahidi / functions.php
Last active May 30, 2025 18:26
GravityForms - Use custom conditional logic to display other fields which are not supported out of the box by GF
<?php
/**
* Validates the custom mask date field format MM/YYYY.
*/
add_filter('gform_field_validation_8', function($result, $value, $form, $field) {
$date_field_ids = [119, 120, 121]; // Field IDs of the custom date field
if (!in_array($field->id, $date_field_ids)) {
return $result;
}
@mujahidi
mujahidi / functions.php
Created October 16, 2024 19:47
Redirect old /hello-world to /blog/hello-world URL
<?php
add_action('template_redirect', 'redirect_old_post_urls');
function redirect_old_post_urls() {
if (is_404()) {
global $wp;
$request = $wp->request;
$post = get_page_by_path($request, OBJECT, 'post');
@mujahidi
mujahidi / append-param.php
Created March 19, 2024 14:10
Pause video when jQuery SLICK slide changes
<?php
// append custom parameters to YouTube iframe to enable JS API
$custom_parameters = '&amp;rel=0&amp;enablejsapi=1';
// Append custom parameters to the src attribute of the iframe
$modified_iframe = preg_replace('/src="(.*?)"/', 'src="$1' . $custom_parameters . '"', $video_iframe);
// For Vimeo video, make sure to append ?api=1
@mujahidi
mujahidi / functions.php
Created October 19, 2023 15:42
Create Woocommerce custom email notification
<?php
$mailer = WC()->mailer();
$template = '/emails/customer-admin-order-status.php';
//format the email
$subject = 'Order Status Update';
$content = wc_get_template_html( $template, array(
'order' => $order,
@mujahidi
mujahidi / functions.php
Last active July 3, 2023 19:03
Multiple instances of same GF form on the same page
<?php
/**
* Multiple instances of same GF form on the same page
*/
add_filter( 'gform_get_form_filter_1', 'gform_get_form_filter_handler', 10, 2 );
add_filter( 'gform_confirmation_1', 'gform_get_form_filter', 10, 2 );
function gform_get_form_filter_handler( $form_string, $form ){
// if form has been submitted, use the submitted ID, otherwise generate a new unique ID
if ( isset( $_POST['gform_random_id'] ) ) {
$random_id = absint( $_POST['gform_random_id'] ); // Input var okay.
@mujahidi
mujahidi / _mixin.scss
Created April 18, 2023 19:05
SASS mixin
$imagePath: "assets/images";
$breakpoints: (
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px,
);
@mujahidi
mujahidi / functions.php
Created April 11, 2023 15:19
READ MORE LESS BUTTON SHORTCODE
<?php
add_shortcode('read_more_less', 'read_more_less_button_handler');
function read_more_less_button_handler( $attrs, $content ){
$title = $attrs['title'];
if( !$title )
$title = "Learn More";
return '
<div class="readmorelessbutton-container">