More examples of using the filter

[ad_1]

@tunyk Certainly. Here’s an example that excludes /cart/, /checkout/, and /thank-you/:

<?php
/**
* Plugin Name: Exclude Shop URLs from Speculative Loading
* Version: 0.1.0
* Author: Weston Ruter
* Plugin URI: https://projectdmc.org/support/topic/more-examples-of-using-the-filter/
* License: GPLv2 or later
* Update URI: false
*/

add_filter(
'plsr_speculation_rules_href_exclude_paths',
function ( $exclude_paths ) {
$exclude_paths[] = '/cart/*';
$exclude_paths[] = '/checkout/*';
$exclude_paths[] = '/thank-you/*';
return $exclude_paths;
}
);

You can duplicate the $exclude_path[] = '...'; line for each additional path you want to exclude.

Put this code into a text file and save the file as something like speculative-loading-shop-exclusions.php and then add that PHP file to a ZIP archive. You can then upload that ZIP file (e.g. speculative-loading-shop-exclusions.zip) to install as a plugin in your WordPress site.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer