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 / Cookie Notifications
Last active December 11, 2020 10:08
Lightweight Cookie Notifications
@thegulshankumar
thegulshankumar / remove-block-editor
Created August 2, 2020 12:04
Remove Block Editor in WordPress
function remove_block_css() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'remove_block_css', 20 );
// disable for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable for post types
add_filter('use_block_editor_for_post_type', '__return_false', 10);
@thegulshankumar
thegulshankumar / Update Ubuntu Server Bash
Created February 7, 2020 18:42
Update Ubuntu Server Bash
#!/bin/bash
TEXT_RESET='\e[0m'
TEXT_YELLOW='\e[0;33m'
TEXT_RED_B='\e[1;31m'
sudo apt update
echo -e $TEXT_YELLOW
echo 'APT update finished...'
echo -e $TEXT_RESET
@thegulshankumar
thegulshankumar / Display Search Results Query in Heading and Title
Created January 28, 2020 23:13
Display Search Results Query in Heading and Title
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const searchTerm = urlParams.get('q');
if (searchTerm) {
const heading = document.querySelector('h1');
const title = document.querySelector('title');
heading.textContent = `Search Results for ${searchTerm}`;
title.textContent = `Search Results for ${searchTerm}`;
}
@thegulshankumar
thegulshankumar / GeneratePress CSE Config
Created January 28, 2020 23:11
GeneratePress CSE Config
// Change Search path in the GeneratePress Theme
add_filter( 'generate_navigation_search_output', function() {
printf(
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" placeholder=" Search" class="search-field" value="%2$s" name="q" title="%3$s" />
</form>',
esc_url( home_url( '/search/' ) ),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
@thegulshankumar
thegulshankumar / gcse-searchresults-only
Last active March 8, 2020 07:51
Display Search Box and Search Results via Google CSE
<div class="gcse-searchbox-only"></div>
<div class="gcse-searchresults-only"></div>
@thegulshankumar
thegulshankumar / Lightweight Social Sharing
Last active December 20, 2019 17:41
Lightweight Social Sharing
<!DOCTYPE html>
<html lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8" />
<title>A super-light-weight Social sharing buttons</title>
<meta name="robots" content="noarchive">
<style>
.resp-sharing-button__link,
@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 / 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 / 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);