Skip to content

Instantly share code, notes, and snippets.

View wpgaurav's full-sized avatar

Gaurav Tiwari wpgaurav

View GitHub Profile
@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);
<?php
function custom_add_schema_attributes() {
if ( is_singular(array('post', 'deal')) ) {
echo ' itemscope itemtype="https://schema.org/Blog"';
}
elseif ( is_singular(array('glossary', 'study_notes')) ) {
echo ' itemscope itemtype="https://schema.org/Article"';
}
elseif ( is_page() ) {
<?php
add_action('init', function() {
register_block_style('core/paragraph', [
'name' => 'note',
'label' => __('Note', 'md'),
'inline_style' => '.is-style-note, .note, .read{background: #fff6c8; border: 1px solid #e4d588; border-radius: 5px; padding: 1em; color: #6D1C71;}'
]);
register_block_style('core/paragraph', [
'name' => 'notice',
'label' => __('Notice', 'md'),
@wpgaurav
wpgaurav / Completely Disable Comments.php
Created October 4, 2024 15:08
Completely Disable Comments in WordPress
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_safe_redirect(admin_url());
exit;
}
@wpgaurav
wpgaurav / Grids.css
Created October 4, 2024 15:07
CSS Grids
.grid-2, .grid-2-fixed, .grid-3,.grid-3-fixed,.grid-4, .grid-4-fixed,.grid-5,.grid-6, .grid-n, .jp-relatedposts-grid {
display: grid;
align-content: stretch;
justify-content: space-evenly;
align-items: stretch;
justify-items: stretch;
row-gap:1em;
column-gap:1em;
}
pyftsubset /Users/gauravtiwari/Downloads/CalSans_Semibold_v1.0.0/fonts/webfonts/CalSans-SemiBold.woff2 \
--unicodes="U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD, U+20B9" \
--flavor="woff2" \
--output-file="CalFont.woff2"