Skip to content

Instantly share code, notes, and snippets.

View wpgaurav's full-sized avatar
🏠
Working from home

Gaurav Tiwari wpgaurav

🏠
Working from home
View GitHub Profile
@wpgaurav
wpgaurav / gt-link-manager-migrator.php
Created March 14, 2026 01:13
GT Link Manager — One-time prefix migration snippet.
@wpgaurav
wpgaurav / tangible-rankmath-integration.php
Created March 6, 2026 10:26
Rank Math SEO: Tangible Loops & Logic block content integration
<?php
/**
* Rank Math SEO: Tangible Loops & Logic block content integration
*
* Feeds tangible/template block content into Rank Math's SEO analysis.
* Supports inline editor templates and selected template posts.
* Does NOT hook the [template] shortcode.
*
* Usage: Drop into functions.php or Code Snippets plugin.
*/
@wpgaurav
wpgaurav / substack-to-mailerpress-importer.php
Last active February 16, 2026 13:05
WP-CLI command to import Substack newsletters into MailerPress campaigns with public URLs.
<?php
/**
* Plugin Name: MailerPress Substack Importer
* Description: WP-CLI command to import Substack newsletters into MailerPress campaigns with public URLs.
* Version: 1.0.0
* Requires PHP: 8.2
*
* Usage:
* wp substack-import https://gauravtiwari.substack.com/feed --dry-run
* wp substack-import https://gauravtiwari.substack.com/feed
@wpgaurav
wpgaurav / inline-small-css.php
Created January 26, 2026 14:14
Inline Small CSS files to reduce render blocking issues. Tested on https://gauravtiwari.org and other sites.
<?php
add_filter('style_loader_tag', 'gt_inline_small_css', 10, 4);
function gt_inline_small_css($tag, $handle, $href, $media) {
// Frontend only - skip admin, customizer, and login
if (is_admin() || is_customize_preview() || $GLOBALS['pagenow'] === 'wp-login.php') {
return $tag;
}
// Size threshold in bytes (15KB)
@wpgaurav
wpgaurav / block-editor-iframe.php
Created April 18, 2025 06:09
Block Editor iFrame Scrolling Fix
<?php
add_action( 'enqueue_block_editor_assets', function() {
wp_add_inline_style( 'wp-edit-post', '
.edit-post-meta-boxes-main {
max-height: unset !important;
height: auto !important;
}
' );
} );
@wpgaurav
wpgaurav / seo-hack.php
Created December 1, 2024 07:52
SEO Hack: Dynamic Meta Keywords
<?php
function gaurav_custom_meta_keywords() {
$keywords = ''; // Initialize keywords variable
if (is_singular('post')) {
// For singular posts, get the terms
$post_id = get_the_ID();
$terms_array = array(); // Initialize terms array
<?php
function add_custom_post_counts() {
$post_types = get_post_types(array('public' => true, '_builtin' => false), 'objects');
foreach($post_types as $post_type) {
$num_posts = wp_count_posts($post_type->name);
$num = number_format_i18n($num_posts->publish);
$text = _n($post_type->labels->singular_name, $post_type->labels->name, intval($num_posts->publish));
if(current_user_can('edit_posts')) {
$output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $num . ' ' . $text . '</a>';
}
<?php
// Disable smart quotes globally
remove_filter('the_content', 'wptexturize');
remove_filter('the_title', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
<?php
function gaurav_custom_meta_keywords() {
$keywords = ''; // Initialize keywords variable
if (is_singular('post')) {
// For singular posts, get the terms
$post_id = get_the_ID();
$terms_array = array(); // Initialize terms array
// Get terms from categories, tags, and custom taxonomies
<?php function remove_post_formats_support() {
remove_theme_support('post-formats');
}
add_action('after_setup_theme', 'remove_post_formats_support', 11);