Skip to content

Instantly share code, notes, and snippets.

View wpgaurav's full-sized avatar
👋
Hello!

Gaurav Tiwari wpgaurav

👋
Hello!
View GitHub Profile
<form id="paypalFeeCalculator">
<div class="form-group">
<label class="form-label">Enter An Amount (USD)</label>
<div class="input-group box-lr">
<span class="input-group-text">$</span>
<input type="number" step="any" id="amount" class="form-control" required>
</div>
</div>
<div class="form-group">
<label class="form-label">Fee Rate</label>
<form id="salesTaxCalculator" class="block-half has-border">
<div class="form-group my-3">
<label class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="taxType" value="exclusive">
<span class="form-check-label">Tax Exclusive</span>
</label>
<label class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="taxType" value="inclusive">
<span class="form-check-label">Tax Inclusive</span>
</label>
@wpgaurav
wpgaurav / gravatars-locally.php
Created November 13, 2023 12:24
Save Gravatars Locally and Display on WordPress Frontend
<?php
// Code begins here. It can be pasted into WPCode or CodeSnippets plugin or functions.php file of your child theme
function my_custom_gravatar($avatar, $id_or_email, $size, $default, $alt) {
$email = '';
if (is_numeric($id_or_email)) {
$id = (int) $id_or_email;
$user = get_userdata($id);
if ($user) $email = $user->user_email;
} elseif (is_object($id_or_email)) {
if (!empty($id_or_email->user_id)) {
@wpgaurav
wpgaurav / add_to_functions.php
Last active September 21, 2023 10:41
Add Custom Template Class to Block Editor Wrapper in the Backend with Marketers Delight theme so that you can customize the editor using CSS. I use this on https://gauravtiwari.org
add_action(
'enqueue_block_editor_assets',
function () {
$theme = wp_get_theme();
wp_enqueue_style(
'block-md-custom-css', '/wp-content/themes/Md/custom-editor.css?v=202310'
);
wp_enqueue_script(
'md-wp-editor-class', '/wp-content/themes/Md/backend-js.js?v=202310');
}
@wpgaurav
wpgaurav / edge-to-edge.css
Created February 19, 2023 14:47
Edge to Edge alignfull in Default Boxed mode of Marketers Delight
@media (max-width:1100px){
/* Also works for .bleed class */
.content-full .alignfull.bleed, .content-full .alignfull, .content-full .bleed {
left:50%;
right:50%;
position:relative;
margin-left: -50vw;
margin-right: -50vw;
max-width: 100vw;
}
@wpgaurav
wpgaurav / safelist.txt
Created October 23, 2022 18:08
WP Rocket CSS Safelist
#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
<?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
<?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
<?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
<?php
function complete_version_removal(){return'';}
add_filter('the_generator','complete_version_removal');
?>