wp_resource_hints
云策文档标注
概述
wp_resource_hints 是一个 WordPress 过滤器,用于修改资源提示(如 DNS 预取、预连接等)的 URL 和属性数组。它允许开发者根据关系类型自定义浏览器预加载行为。
关键要点
- 过滤器名称:wp_resource_hints,用于过滤资源提示的 URL 和属性。
- 参数:$urls(资源数组或 URL 字符串)和 $relation_type(关系类型,如 'dns-prefetch'、'preconnect' 等)。
- 资源属性:包括 href(必需)、as、crossorigin、pr、type 等,用于定义资源的行为和特性。
- 版本历史:从 WordPress 4.6.0 引入,4.7.0 增强了 $urls 参数以支持属性数组。
- 相关函数:wp_resource_hints() 用于输出资源提示到浏览器。
原文内容
Filters domains and URLs for resource hints of the given relation type.
Parameters
$urlsarray- Array of resources and their attributes, or URLs to print for resource hints.
...$0array|stringArray of resource attributes, or a URL string.hrefstringURL to include in resource hints. Required.asstringHow the browser should treat the resource (script,style,image,document, etc).crossoriginstringIndicates the CORS policy of the specified resource.prfloatExpected probability that the resource hint will be used.typestringType of the resource (text/html,text/css, etc).
$relation_typestringThe relation type the URLs are printed for. One of'dns-prefetch','preconnect','prefetch', or'prerender'.Source
$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );Changelog
User Contributed Notes
You must log in before being able to contribute a note or feedback.