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 / smart-404.html
Created April 20, 2024 16:13
Smart-404.html for Redirecting Deprecated Translated Pages to English Version 🚀
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>example.com</title>
<style>
body, html {
height: 100%;
margin: 0;
<?php
/**
* Special condition: If your WordPress has a settings to automatically approve all comments without a manual approval
* In this case, Cloudflare plugin may not purge the cache.
* This is a quick-workaround. After adding this snippet,
* you need to create a rule to bypass the Cache for comment-posted=true query string
*/
add_filter( 'comment_post_redirect', 'redirect_after_comment' );
function redirect_after_comment( $location ) {
@thegulshankumar
thegulshankumar / Flush DNS Cache
Created August 26, 2023 05:00
Flush DNS Cache
Google Public DNS (8.8.8.8, 8.8.4.4)
https://dns.google/cache
Cloudflare DNS (1.1.1.1, 1.0.0.1)
https://1.1.1.1/purge-cache/
OpenDNS (208.67.222.222, 208.67.220.220)
@thegulshankumar
thegulshankumar / Bypass CDN Caching using functions.php
Created August 9, 2023 04:31
Bypass CDN Caching using functions.php
<?php // Exclude this opening tag.
/**
* The template_redirect action hook allows pre-template actions.
* We set s-maxage to 0 to ensure CDNs fetch fresh content,
* assuming the CDN respects existing headers.
*/
add_action('template_redirect', function () {
header('cache-control: s-maxage=0');
});
@thegulshankumar
thegulshankumar / Display a Quick Summary for the News Article.php
Last active August 4, 2023 14:10
Display a Quick Summary for the News Article
/**
* News Summary: Display the most important information first.
*
* This code snippet adds a custom meta box called "News Summary" in the Post editor.
* The meta box allows users to input a summary for each post, which will be displayed
* at the beginning of the post's content on the single post page.
*/
// Register the Summary Meta Box
function custom_news_summary_meta_box() {
@thegulshankumar
thegulshankumar / Bulk Migrate All Published Posts to Draft Status via WP CLI
Created August 1, 2023 07:45
Bulk Migrate All Published Posts to Draft Status via WP CLI
wp post list --post_type=post --format=ids --allow-root | xargs wp post update --post_status=draft --allow-root
or
wp post update $(wp post list --post_type=post --format=ids --allow-root) --post_status=draft --allow-root
@thegulshankumar
thegulshankumar / Backup WordPress at BunnyCDN Edge Storage
Created March 20, 2023 08:25
Backup WordPress at BunnyCDN Edge Storage
#!/bin/bash
# Define variables
WORDPRESS_ABSPATH="/var/www/html"
BUNNYCDN_EDGE_STORAGE_ZONE_URL="https://storage.bunnycdn.com"
BUNNYCDN_EDGE_STORAGE_NAME="example-org-backup"
BUNNYCDN_EDGE_STORAGE_PASSWORD="ENTER-STORAGE-SPECIFIC-PASSWORD-HERE-NOT-ACCOUNT-API"
# Check if WP CLI is installed
@thegulshankumar
thegulshankumar / Basic NGINX Rules for WordPress
Created December 27, 2020 14:44
Basic NGINX Rules for WordPress
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
# Document Root
root /var/www/html;
index index.php index.html index.htm;
server_name demo.gulshankumar.net;
client_max_body_size 0;
@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);