wp_strict_cross_origin_referrer()
概述
wp_strict_cross_origin_referrer() 函数用于输出一个 referrer strict-origin-when-cross-origin meta 标签,以控制跨源资源加载时的 referrer 信息发送行为。
关键要点
- 该函数输出一个 meta 标签,告诉浏览器在加载跨源资产时不要发送完整 URL 作为 referrer 到其他站点。
- 典型用法是作为 'wp_head' 钩子的回调函数:add_action( 'wp_head', 'wp_strict_cross_origin_referrer' );
- 该函数在 WordPress 5.7.0 版本中引入。
代码示例
add_action( 'wp_head', 'wp_strict_cross_origin_referrer' ); Displays a referrer strict-origin-when-cross-origin meta tag.
Description
Outputs a referrer strict-origin-when-cross-origin meta tag that tells the browser not to send the full URL as a referrer to other sites when cross-origin assets are loaded.
Typical usage is as a ‘wp_head’ callback:
add_action( 'wp_head', 'wp_strict_cross_origin_referrer' );
Source
function wp_strict_cross_origin_referrer() {
?>
<meta name='referrer' content='strict-origin-when-cross-origin' />
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/general-template.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/general-template.php#L3562">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/general-template.php#L3562-L3566">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="used-by"><figure class="wp-block-table "><table><thead><tr><th scope="col">Used by</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_sensitive_page_meta/">wp_sensitive_page_meta()</a><code>wp-includes/deprecated.php
Display a noindex,noarchive meta tag and referrer strict-origin-when-cross-origin meta tag.
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |