Skip to content

Instantly share code, notes, and snippets.

View thegulshankumar's full-sized avatar
🎯
Focusing on regular work

Gulshan Kumar thegulshankumar

🎯
Focusing on regular work
View GitHub Profile
@thegulshankumar
thegulshankumar / Google Analytic Code-with-cookies-domain
Created July 12, 2017 06:17
Google Analytics Tracking With Cookie 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 / Font Awesome Social Icons
Created June 30, 2017 05:25
Learn how to add Social Icons with Font Awesome
<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css?ver=4.4.0' type='text/css' media='all'/>
<style type="text/css">
.gkprofile
ul {
overflow: auto;
}
.gkprofile ul li {
list-style-type: none;
float: left;
function first_amp_ad() {
return '<amp-ad
layout="fixed-height"
height=100
type="adsense"
type="amp_ad"
data-ad-client="ca-pub-xxxxxxxxxxxxxx"
data-ad-slot="xxxxxxxxx">
</amp-ad>';
}
@thegulshankumar
thegulshankumar / gist:474164f3b2cf73dbcf11c556812af48b
Created September 14, 2017 05:08
Leverage browsing cache via .htaccess
# 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 / Redirect from HTTPS to HTTP
Created October 24, 2017 04:08
Redirect from HTTPS to HTTP
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@thegulshankumar
thegulshankumar / amp
Created August 14, 2017 06:07
Remove output of rel=amphtml in official AMP plugin (WordPress)
<?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 / ServerPilot wp-config.php
Created April 24, 2018 06:43
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);
@thegulshankumar
thegulshankumar / Block Google AdSense in Some Country
Created April 27, 2018 06:43
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
@thegulshankumar
thegulshankumar / Disable Adsense Ads From 404
Created March 19, 2019 09:20
Disable Adsense Ads From 404 Pages In Wordpress
/*
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');
@thegulshankumar
thegulshankumar / gist:c7fb8d0d9e9cc6e4161bc45fdf2d1155
Last active November 18, 2019 23:31
A light weight Back to top in jQuery
<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();