Skip to content

Instantly share code, notes, and snippets.

View isaumya's full-sized avatar
👨‍💻
Think Twice, Code Once

Saumya Majumder isaumya

👨‍💻
Think Twice, Code Once
View GitHub Profile
@isaumya
isaumya / cf_cache_rules_implementation_guide_spcc.md
Last active April 19, 2024 09:11
Super Page Cache for Cloudflare — Guide for using Remove Cache Buster Query Parameter feature (when using Cache Everything page rule)

Implementation Guide for using "Remove Cache Buster Query Parameter" feature

The Super Page Cache for Cloudflare plugin has recently added the feature for using the Cache Everything pagerule withing the ?swcfpc=1 cache buster query paramater. This opens up so many new doors where users previously had to use the Cloudflare Workers to remove the cache buster.

With this new option now users are able to take advantage of Cloudflare Cache Everything page rule and take it to the next level by using the new Rulesets released by Cloudflare. Basically this is achived by taking advantage of the all new Cache Rules feature implemented by Cloudflare.


Setp 1 — Setting up the Cache Rules inside your Cloudflare Dashboard

The first thing that you need to do is, log-in to your Cloudflare Dahsbord and go to the domain/zone doe which you are setting up the [Super Page Cache for Cloudflare](https://wordpress.org/plug

@isaumya
isaumya / remove_unused_gutenberg_block.md
Created October 25, 2022 08:18
Remove the unnecessary/unused Gutenberg blocks and block variations

Remove Unused Gutenberg Blocks and Block Variations

When creating custom WordPress themes, we often create custom Gutenberg blocks as per the website design and development need. As a result the list of available block keep getting increased and sometimes it gets really hard to quickly find the block you are looking for. WordPress being a great CMS, it comes with a lot of in-built core blocks, but not all website need them or use them.

So, if you are also building a custom WordPress theme where you would like to unregister some of the default Gutenberg blocks that WordPress ships with you can do that easily by following the steps below.

⚠️ Note: Read the code first and then only unregister the blocks you don't want. Don't blindly copy paste the code.

Setp 1 — Create editor.js inside your theme

Create a JavaScript file inside your WordPress theme. You can name the file whatever you like and also put it whereever you prefer inside your theme file structure. Here for example, I've named the file `

@isaumya
isaumya / wp-rocket-no-cache-installation-guide.md
Last active April 8, 2024 08:51
WP Rocket + Super Page Cache for Cloudflare : Disabling WP Rocket Page caching for it to work with Super Page Cache for Cloudflare

WP Rocket (No Page Cache) - Must Use Plugin - Installation Guide

When using Super Page Cache for Cloudflare along with WP Rocket plugin it is highly recommended that you do not use more than one page caching system on your site as that will lead to compatibility issues and problems.

Whether you have a server level page caching system or some other page caching plugin installed in yoru site, you need to ensure that all page caching mechanisms are disabled on those plugin before using the Super Page Cache for Cloudflare plugin on your website. Also, ensure that there is no server rule in your .htaccess file or nginx.conf file which is modifying the cache-control header value of the page as that value needs to be managed by the Super Page Cache for Cloudflare plugin.

Here is what you should do if you are uising WP Rocket along with Super Page Cache for Cloudflare to get the best results.

Step 1 - Make sure you have a clean sl

@isaumya
isaumya / wpcspc_device_based_cache_cf_worker_template.js
Last active February 18, 2023 22:50
Custom Cloudflare Worker Code for Device Based Caching - WP Cloudflare Super Page Cache Plugin
/**
* Worker Name: WPCSPC - Device based Cache
* Description: This worker is responsible for caching the requests based on the device type
* Based on Default Worker Version: 2.8.0
* Version: 2.1.0
* @link: https://wordpress.org/plugins/wp-cloudflare-page-cache/
* @link: https://wordpress.org/support/topic/mobile-page-theme-and-cloudflare-caching-plugin-integration/
* @author: Saumya Majumder
*/
// Default cookie prefixes for cache bypassing
@isaumya
isaumya / cloudflare-cdn-routing-anomaly-detailed-test.md
Created February 28, 2021 12:35
Cloudflare CDN Routing Anomaly detailed test across multiple DNS resolvers

Cloudflare CDN Routing Anomaly Detailed Test Across Multiple DNS Resolvers

Here are some key details about my testing location and ISP:

Important Note: Keep an eye on the value of colo on the following response. As that value will show exactly from which Cloudflare CDN edge the data is getting served from. Moreover these 3 letter colo values are basically the IATA airport code on that city. So, you can use a website like World Airport Codes to find out the exact City and Country Name.

@isaumya
isaumya / customize-woocommerce-checkout-fields.php
Created August 21, 2020 10:31
Customizing WooCommerce Core Checkout Fields (Removing Address Line 2) and also change the placeholder text of Address Line 1
<?php
/**
* Remove Address Line 2 from WooCommerce Billing & Shipping Form
* Also add proper placeholder for Address line 1 to include the full address
* @author Acnam Infotech
*/
add_filter( 'woocommerce_checkout_fields', function( $fields ) {
if( is_array( $fields ) ) {
// Remove Address Line 2 from Billing & Shipping fields
unset( $fields['billing']['billing_address_2'] );
@isaumya
isaumya / manage-redirection-and-add-security-headers-via-cloudflare-workers.js
Last active March 15, 2022 19:02
Cloudflare Workers code to manage redirection of a domain and adding extra security headers to the correct hostname
/**
* CloudFlare Worker to handle each request
* and based on the given condition either redirect it to
* the proper URL
* OR add the security headers in case of Status 200
* @author Acnam Infotech
* @explanation https://acnam.com/why-and-how-to-use-cloudflare-workers-explained-with-sample-code/
*/
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
@isaumya
isaumya / remove-woocommerce-bloat-marketing-hub.md
Last active April 10, 2024 12:45
Easily Remove WooCommerce Bloated Features like Marketing Hub from WordPress Admin Menu

Remove WooCommerce Bloated Features from WP Admin Menu

Recently WooCommerce has added a lot of improvements to the plugin which we really appriciate but at the same time a lot of bloated features has alos been added to the plugin like Marketing Hub, a completely useless menu taking extra space among the other important menu items. Now if you find Marketing Hub to be useful, you can keep it.

But just in case you are looking for a way to remove these features that you no longer need from your WordPress Admin menus, take a look at the following code snippets. Please note: though I will show you how you can remove the Marketing Hub from your WP Admin menu list completely and make sure WooCommerce doesn't execute codes for that feature you don't need, you can do the same for other WooCommerce features as well like Analytics.

How to remove Marketing Hub for WooCommerce <= v4.2

If you are using WooCommerce <= v4.2, you can simple add this one line of code in your theme's functions.php f

@isaumya
isaumya / woocommerce-conditional-product-shipping-cost.md
Created May 12, 2020 07:48
Enable or Disable Free Shipping or Flat Rate Shipping Based On WooCommerce Product

Let's say you have a product for which you just want to show the Free Shipping option or the Flat Rate shipping option, you can easuly do it using the following filters.

Hide The Flat Rate SHipping Option For Certain WooCommerce Product

add_filter( 'woocommerce_shipping_flat_rate_is_available', function( $is_available ) {
	// set the product ids that are eligible
	$eligible = array( '1711' );

	// get cart contents
@isaumya
isaumya / get-product-price-by-id-woocommerce.md
Created April 29, 2020 05:38
A function to get the simple product or variation product's price by passing the product_is or variation_id in WooCommerce.

When to use it?

Lets say in your template you are doing something like a pricing table, where instead of manually putting the price, you just want to pass the variation_id or the product_id (in case of simple product and dynamically get the price of the product.

This is helpful in many cases:

  • You don't have to manage price in two places & if you update the price of the product it will be reflected everywhere.
  • If you are using country based pricing and want to show the price accordingly.

The Function