Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Gaurav Tiwari wpgaurav

🎯
Focusing
View GitHub Profile
@wpgaurav
wpgaurav / safelist.txt
Created October 23, 2022 18:08
WP Rocket CSS Safelist
View safelist.txt
#wp-custom(.*)
/wp-content/uploads/generateblocks/(.*).css
(.*)#ez-toc(.*)
(.*)#gspb(.*)
(.*).aawp(.*)
(.*).alert
(.*).align(.*)
(.*).animate
(.*).box(.*)
(.*).button
@wpgaurav
wpgaurav / wp-image-sizes.php
Created September 21, 2022 03:28
Support for Post Thumbnails & Custom Thumbnail Sizes in WordPress and Add those sizes to Block Editor/Gutenberg
View wp-image-sizes.php
<?php
add_action( 'init', function() {
add_image_size( 'rename-this', 1200, 500, false );
add_image_size( 'rename-again', 550, 550, true );
} );
// Add these sizes to Gutenberg
add_filter( 'image_size_names_choose','md_custom_image_sizes_gb' );
function md_custom_image_sizes_gb( $sizes ) {
@wpgaurav
wpgaurav / wooc-scripts-limit.php
Created September 21, 2022 03:25
Load WooCommerce Scripts only When Needed
View wooc-scripts-limit.php
<?php add_action('wp_enqueue_scripts', 'myown_remove_scripts');
function myown_remove_scripts(){
if ( function_exists( 'is_woocommerce' ) ) {
//dequeue scripts and styles from not WC pages
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce-layout');
wp_dequeue_style( 'woocommerce-smallscreen');
wp_dequeue_style( 'woocommerce-general');
wp_dequeue_script( 'wc_price_slider' );
@wpgaurav
wpgaurav / revision-limit.php
Created September 21, 2022 03:23
Limit the maximum number of post revisions stored on Database
View revision-limit.php
<?php
if(!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS',10);
?>
@wpgaurav
wpgaurav / generator-remove.php
Created September 21, 2022 03:22
Hide from readers that you are using WordPress or WooCommerce or any other Custom Frameworks
View generator-remove.php
<?php
function complete_version_removal(){return'';}
add_filter('the_generator','complete_version_removal');
?>
@wpgaurav
wpgaurav / login-logo.php
Created September 21, 2022 03:21
Replace the default WordPress Login Logo with your site’s custom header image
View login-logo.php
<?php
function namespace_login_style(){
if( function_exists('get_custom_header')){
$width = get_custom_header()->width;
$height = get_custom_header()->height;
} else {
$width = HEADER_IMAGE_WIDTH;
$height = HEADER_IMAGE_HEIGHT;}
echo ''.PHP_EOL;}
?>
@wpgaurav
wpgaurav / author-redirect-to-about.php
Created September 21, 2022 03:19
Redirect Author Archives to ‘About’ page
View author-redirect-to-about.php
<?php add_filter( 'author_link', 'my_author_link' ); function my_author_link() { return home_url( 'about' ); } ?>
@wpgaurav
wpgaurav / remove-featured-images-from-db.php
Last active September 21, 2022 03:18
Batch remove all featured images from your WordPress posts and pages
View remove-featured-images-from-db.php
@wpgaurav
wpgaurav / seomonth.php
Last active September 16, 2022 01:29
New shortcode [seomonth] that renders next month from 21st of this month
View seomonth.php
<?php
// you can change 20 on line #8 to any date between 1 to 27
add_shortcode( 'seomonth' , 'gtrmd_seomonthyear' );
function gtrmd_seomonthyear() {
$gtseomonthyear1 = date_i18n("F");
$gtseomonthyear2 = date("F", strtotime ( '+1 month' , strtotime ( $gtseomonthyear1 ) )) ;
$gtdtseocheck = date("j");
if($gtdtseocheck > 20){
return "$gtseomonthyear2";
} else{
@wpgaurav
wpgaurav / cookie-notice.php
Last active September 3, 2022 06:45
Add minimalistic Cookie Notice
View cookie-notice.php