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 / remove-date-time-from-gp-theme.php
Created May 2, 2024 08:54
Remove Date & Time in GeneratePress Comment section
<?php // Place this snippet in the functions.php file or use the Code Snippets plugin without PHP opening tags
/*
* Concepts behind the solution
* Google says: If you've followed the best practices above
* and find incorrect dates are being selected,
* consider if you can remove or minimize other dates that may appear on the page.
* https://developers.google.com/search/blog/2019/03/help-google-search-know-best-date-for
*
* Note: It worked for us.
@thegulshankumar
thegulshankumar / Restoring Category Assignments: Reconnecting Posts with their Category.php
Created April 30, 2024 14:02
Restoring Category Assignments: Reconnecting Posts with their Category
<?php
/*
Yikes! I deleted a category in WordPress by mistake. Now what?
Well, if you have an old backup, you can extract the list of Post IDs from that specific category.
This is an alternative approach to restoring the entire backup.
Let's say the category name was 'College & Admission' with the slug 'college-admission'.
@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;