Skip to content

Instantly share code, notes, and snippets.

View dipakcg's full-sized avatar
🎯
Focusing

Dipak C. Gajjar dipakcg

🎯
Focusing
View GitHub Profile
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 October 28, 2020 07:13
WordPress : Load any third-party script locally
@dipakcg
dipakcg / wp-config.php
Created September 23, 2018 05:09 — forked from MikeNGarrett/wp-config.php
Disable admin-ajax on the front-end of WordPress sites and cache the resulting 404.
<?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 April 15, 2017 07:54
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 10:55
WordPress - Force all scripts to footer
/* ******************
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 March 26, 2016 20:25
Example of an add-on with Freemius that is activated only when the parent plugin is activated and loaded.
<?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 November 7, 2024 08:58
All those damned wp-config constants you can never remember.
<?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 August 31, 2020 15:28
Parallelize downloads across hostnames for WordPress. Useful to boost static resources load speed on websites. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
<?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 August 22, 2016 14:00
WordPress - Display Google Custom Search results if no posts/results found.
<?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 August 29, 2014 17:26
WordPress - Disable Plugin Update Notification For A Specific WordPress Plugin
/* 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' );