apply_filters( ‘wp_speculation_rules_href_exclude_paths’, string[] $href_exclude_paths, string $mode )

Filters the paths for which speculative loading should be disabled.

Description

All paths should start in a forward slash, relative to the root document. The * can be used as a wildcard.
If the WordPress site is in a subdirectory, the exclude paths will automatically be prefixed as necessary.

Note that WordPress always excludes certain path patterns such as /wp-login.php and /wp-admin/*, and those cannot be modified using the filter.

Parameters

$href_exclude_pathsstring[]
Additional path patterns to disable speculative loading for.
$modestring
Mode used to apply speculative loading. Either 'prefetch' or 'prerender'.

Source

$href_exclude_paths = (array) apply_filters( 'wp_speculation_rules_href_exclude_paths', array(), $mode );

Changelog

VersionDescription
6.8.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Note: All paths must start with a forward slash and are evaluated relative to the root document. The asterisk (*) can be used as a wildcard.

    Example: The following code ensures that any URL starting with /go/ (e.g. ‘example.com/go/wp1234/‘) is completely excluded from speculative loading rules:

    add_filter( 'wp_speculation_rules_href_exclude_paths', function( $href_exclude_paths ) {$href_exclude_paths[] = '/go/*';
    return $href_exclude_paths;
    });

You must log in before being able to contribute a note or feedback.