Busting Browser Cache when updating stylesheet of WordPress website

If you are editing the child theme CSS then this line has nothing to do with that: wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’, [], THEME_VERSION, ‘all’); get_template_directory_uri always refers to the parent theme, get_stylesheet_directory_uri always refers to the active theme, in this case the child theme. Likewise these lines refer to the currently active theme, aka … Read more

Private plugin updating – GitHub zip file changes the plugin directory (with release or branch name)

It should be possible to carefully adjust the destination path via the upgrader_package_options filter in WordPress, before the upgrader installs the new version of it. Here’s a barebone example that appends the plugin’s current directory name to the destination path, if it’s same as WP_PLUGIN_DIR (see check in core here), when the package url is … Read more

How to display featured image caption only if exists?

I am a “little late” but this solution worked great for me. It will show the div only if the caption is not empty. <?php $get_description = get_post(get_post_thumbnail_id())->post_excerpt; the_post_thumbnail(); if(!empty($get_description)){//If description is not empty show the div echo ‘<div class=”featured_caption”>’ . $get_description . ‘</div>’; } ?>

PHP Add products to cart with WooCommerce Addons

The WooCommerce Cart add_to_cart function takes a parameter for cart_item_data. To make this work, you simply need to pass the addon data to add_to_cart. Something like this: $addons = array( array( “name” => “Size”, “value” => “2.5×7”, “price” => 0, “field_name” => “5186-0”, “field_type” => “multiple_choice”, “id” => “1683555538”, “price_type” => “flat_fee” ), array( “name” … Read more

Unable to register a block using block.json in Block Editor

The section titled Live rendering in the block editor on the WordPress documentation page, Creating dynamic blocks, has sample code demonstrating how to use server-side rendering. The documentation page says: Gutenberg 2.8 added the <ServerSideRender> block which enables rendering to take place on the server using PHP rather than in JavaScript. Rather than setting edit: … Read more

Edit Page button is gone

Check under settings -> reading and select the page where you want to show your blog posts. Then this becomes your blog page. You can set it to the home page or choose a static page for your home page. See more info here: https://wordpress.org/documentation/article/settings-reading-screen/ You usually can’t change the layout/content of the blog page … Read more

Sharing plugin tables between 2 sites in the same database

I’ve created an alternative wp-config.php and renamed to wp-config2.php with the same configuration except for the table prefix. Then I tried by editing all the plugin files. At the top of each file I found: if ( ! defined( ‘ABSPATH’ ) ) { exit; // Exit if accessed directly! } And I replaced it for: … Read more