Skip to content

Instantly share code, notes, and snippets.

Gulshan Kumar thegulshankumar

View GitHub Profile
@thegulshankumar
thegulshankumar / Disable Adsense Ads From 404
Created Mar 19, 2019
Disable Adsense Ads From 404 Pages In Wordpress
View Disable Adsense Ads From 404
/*
Instructions
Step 1. Remove adsbygoogle.js from all Ad units
Step 2. Paste below snippet in the Theme functions.php or use Code Snippets plugin
*/
function conditional_adsense_display() {
if ( ! is_404( ) ) echo '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>';}
add_action('wp_head', 'conditional_adsense_display');
View Block Google AdSense in Some Country
// Untested: May not work with some Cache plugin.
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
if ($country_code == "US") {
echo "<style>.aicp {display:none;}</style>";
}else {
echo "<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>";
}
// Block multiple countries
<?php
View ServerPilot wp-config.php
define('SP_REQUEST_URL', ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', SP_REQUEST_URL);
define('WP_HOME', SP_REQUEST_URL);
View Redirect from HTTPS to HTTP
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
View gulshankumar.net-blog-profiles
Gulshan Kumar (Born on 21st July in Bihar) is an Indian professional blogger, a dreamer, a positive thinker. Learn more at https://www.gulshankumar.net/about/
@thegulshankumar
thegulshankumar / gist:c7fb8d0d9e9cc6e4161bc45fdf2d1155
Last active Sep 24, 2017
A light weight Back to top in jQuery
View gist:c7fb8d0d9e9cc6e4161bc45fdf2d1155
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css?ver=4.8.2' type='text/css' />
<a class="back-to-top" title="Page Up" style="color: #eadede; font-size:32px; position: fixed; bottom:20px; right:15px;" href="#top"><i class="fa fa-arrow-circle-up" aria-hidden="true"></i></a>
<script>
var jQuerybackToTop = jQuery(".back-to-top");
jQuerybackToTop.hide();
jQuery(window).on('scroll', function() {
if (jQuery(this).scrollTop() > 400) { // Show button after X scroll
jQuerybackToTop.fadeIn();
} else {
jQuerybackToTop.fadeOut();
@thegulshankumar
thegulshankumar / gist:474164f3b2cf73dbcf11c556812af48b
Created Sep 14, 2017
Leverage browsing cache via .htaccess
View gist:474164f3b2cf73dbcf11c556812af48b
# Leverage Browser Caching by setting HTTP header expires
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 0 seconds"
# CSS
ExpiresByType text/css "access plus 1 month"
# Data Interchange
ExpiresByType application/json "access plus 0 seconds"
@thegulshankumar
thegulshankumar / amp
Created Aug 14, 2017
Remove output of rel=amphtml in official AMP plugin (WordPress)
View amp
<?php
// Callbacks for adding AMP-related things to the main theme
/** Using comment syntax at amp/includes/amp-frontend-actions.php file.
add_action( 'wp_head', 'amp_frontend_add_canonical' );
function amp_frontend_add_canonical() {
if ( false === apply_filters( 'amp_frontend_show_canonical', true ) ) {
return;
}
@thegulshankumar
thegulshankumar / Google Analytic Code-with-cookies-domain
Created Jul 12, 2017
Google Analytics Tracking With Cookie Domain
View Google Analytic Code-with-cookies-domain
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', {'cookieDomain': 'www.example.com'});
ga('send', 'pageview');
</script>
@thegulshankumar
thegulshankumar / shorte.st-website-script
Created Jul 12, 2017
Shorte.st URL Tool: Website Monetization Script
View shorte.st-website-script
<script type="text/javascript">//<![CDATA[
(function() {
var configuration = {
// Please replace with own token ID https://shorte.st/tools/api
"token": "538bed99daee6eba8d667a8562f6e266",
"excludeDomains": [
// Please write below your domain name
"yourowndomain.com"
],
"capping": {
You can’t perform that action at this time.