Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Dipak C. Gajjar dipakcg

🎯
Focusing
View GitHub Profile
View gist:8bf7e4155fd55e71c6f7c3e28e286f4a
This is the technique I use to defer Youtube videos, when optimising the performance of WordPress site.
(1) Replace Youtube iFrame embed code with the below one:
----------------------
<div class="dcg-responsive-container">
<iframe class="dcg-responsive-iframe" src="" data-src="https://www.youtube.com/watch?v=nEFZLFyZNcE?rel=0" frameborder="0" allowfullscreen style="border:0"></iframe>
</div>
(2) Add the following CSS element (stylesheet element that will make Youtube iFrame Responsive) (style.css?):
@dipakcg
dipakcg / footer.php
Last active Oct 28, 2020
WordPress : Load any third-party script locally
View footer.php
@dipakcg
dipakcg / wp-config.php
Created Sep 23, 2018 — forked from MikeNGarrett/wp-config.php
Disable admin-ajax on the front-end of WordPress sites and cache the resulting 404.
View wp-config.php
<?php
if(
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false &&
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false
) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' );
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" );
die;
@WganMe
WganMe / mod_pagespeed module for CPanel WHM
Created Apr 15, 2017
mod_pagespeed module for CPanel WHM
View mod_pagespeed module for CPanel WHM
yum install ea4-experimental
yum install ea-apache24-mod_pagespeed
@dipakcg
dipakcg / functions.php
Last active May 14, 2017
WordPress - Force all scripts to footer
View functions.php
/* ******************
When considering performance speed, you may want to keep JS scripts organized beneath your overall page HTML.
This snippet allows most of the DOM to finish loading before running any dynamic scripts.
****************** */
function dcg_move_scripts_to_footer() {
if( !is_admin() ) {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
@vovafeldman
vovafeldman / fs-my-addon.php
Created Mar 26, 2016
Example of an add-on with Freemius that is activated only when the parent plugin is activated and loaded.
View fs-my-addon.php
<?php
/*
Plugin Name: My Add-on
Version: 1.0.0
Author: Vova Feldman
Author URI: http://freemius.com
License: GPL2
*/
// Exit if accessed directly
@MikeNGarrett
MikeNGarrett / wp-config.php
Last active Jan 11, 2022
All those damned wp-config constants you can never remember.
View wp-config.php
<?php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
@leowebguy
leowebguy / parallelize.php
Last active Aug 31, 2020
Parallelize downloads across hostnames for WordPress. Useful to boost static resources load speed on websites. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
View parallelize.php
<?php
/******
Parallelize downloads across hostnames for WordPress.
Useful to boost static resources load speed on websites.
Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
See full post > https://medium.com/p/32e9dc2fec0c
In order to work properly, all subdomains/hostnames MUST have the same structure/path. Ex:
http://mydomain.com/wp-content/uploads/2015/11/myimage.jpg
@dipakcg
dipakcg / search.php
Last active Aug 22, 2016
WordPress - Display Google Custom Search results if no posts/results found.
View search.php
<?php
/* Below code will display Google Custom Search results if no posts/results found */
/* Add the below code in theme's search.php file where you want to display results from Google */
$query = get_search_query();
$query_new =str_replace(' ','%20',$query);
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=0&rsz=8&q=".$query_new;
$body = file_get_contents($url);
$json = json_decode($body);
@dipakcg
dipakcg / functions.php
Created Aug 29, 2014
WordPress - Disable Plugin Update Notification For A Specific WordPress Plugin
View functions.php
/* Put this code in current theme’s functions.php */
/* Replace plugin-directory/plugin-file.php with plugin’s directory and file name */
function filter_plugin_updates( $value ) {
unset( $value->response['plugin-directory/plugin-file.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );