钩子文档

wp_speculation_rules_href_exclude_paths

💡 云策文档标注

概述

wp_speculation_rules_href_exclude_paths 是一个 WordPress 过滤器,用于禁用特定路径的推测性加载(speculative loading)。它允许开发者添加额外的路径模式,以排除这些路径的预取或预渲染行为。

关键要点

  • 过滤器名称:wp_speculation_rules_href_exclude_paths
  • 用途:过滤应禁用推测性加载的路径
  • 路径格式:所有路径应以正斜杠开头,相对于根文档;可使用 * 作为通配符
  • 子目录处理:如果 WordPress 站点位于子目录中,排除路径会自动添加必要的前缀
  • 内置排除:WordPress 始终排除某些路径模式(如 /wp-login.php 和 /wp-admin/*),这些无法通过此过滤器修改
  • 参数:$href_exclude_paths(字符串数组,要禁用推测性加载的额外路径模式)和 $mode(字符串,推测性加载的模式,'prefetch' 或 'prerender')
  • 源代码示例:$href_exclude_paths = (array) apply_filters( 'wp_speculation_rules_href_exclude_paths', array(), $mode );
  • 相关函数:wp_get_speculation_rules() 用于返回基于配置的完整推测规则数据
  • 引入版本:6.8.0

📄 原文内容

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

Version Description
6.8.0 Introduced.