mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Robots: Introduce Robots API.
This changeset introduces a filter-based Robots API, providing central control over the `robots` meta tag.
* Introduces `wp_robots()` function which should be called anywhere a `robots` meta tag should be included.
* Introduces `wp_robots` filter which allows adding or modifying directives for the `robots` meta tag. The `wp_robots()` function is entirely filter-based, i.e. if no filter is added to `wp_robots`, no directives will be present, and therefore the entire `robots` meta tag will be omitted.
* Introduces the following `wp_robots` filter functions which replace similar existing functions that were manually rendering a `robots` meta tag:
* `wp_robots_noindex()` replaces `noindex()`, which has been deprecated.
* `wp_robots_no_robots()` replaces `wp_no_robots()`, which has been deprecated.
* `wp_robots_sensitive_page()` replaces `wp_sensitive_page_meta()`, which has been deprecated. Its rendering of the `referrer` meta tag has been moved to another new function `wp_strict_cross_origin_referrer()`.
Migration to the new functions is straightforward. For example, a call to `add_action( 'wp_head', 'wp_no_robots' )` should be replaced with `add_filter( 'wp_robots', 'wp_robots_no_robots' )`.
Plugins and themes that render their own `robots` meta tags are encouraged to switch to rely on the `wp_robots` filter in order to use the central management layer now provided by WordPress core.
Props adamsilverstein, flixos90, timothyblynjacobs, westonruter.
See #51511.
git-svn-id: https://develop.svn.wordpress.org/trunk@49992 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -3191,59 +3191,17 @@ function wlwmanifest_link() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a noindex meta tag if required by the blog configuration.
|
||||
* Displays a referrer strict-origin-when-cross-origin meta tag.
|
||||
*
|
||||
* If a blog is marked as not being public then the noindex meta tag will be
|
||||
* output to tell web robots not to index the page content. Add this to the
|
||||
* {@see 'wp_head'} action.
|
||||
*
|
||||
* Typical usage is as a {@see 'wp_head'} callback:
|
||||
*
|
||||
* add_action( 'wp_head', 'noindex' );
|
||||
*
|
||||
* @see wp_no_robots()
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
function noindex() {
|
||||
// If the blog is not public, tell robots to go away.
|
||||
if ( '0' == get_option( 'blog_public' ) ) {
|
||||
wp_no_robots();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a noindex meta tag.
|
||||
*
|
||||
* Outputs a noindex meta tag that tells web robots not to index the page content.
|
||||
* Typical usage is as a {@see 'wp_head'} callback. add_action( 'wp_head', 'wp_no_robots' );
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @since 5.3.0 Echo "noindex,nofollow" if search engine visibility is discouraged.
|
||||
*/
|
||||
function wp_no_robots() {
|
||||
if ( get_option( 'blog_public' ) ) {
|
||||
echo "<meta name='robots' content='noindex,follow' />\n";
|
||||
return;
|
||||
}
|
||||
|
||||
echo "<meta name='robots' content='noindex,nofollow' />\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a noindex,noarchive meta tag and referrer origin-when-cross-origin meta tag.
|
||||
*
|
||||
* Outputs a noindex,noarchive meta tag that tells web robots not to index or cache the page content.
|
||||
* Outputs a referrer 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_sensitive_page_meta' );
|
||||
* Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_strict_cross_origin_referrer' );
|
||||
*
|
||||
* @since 5.0.1
|
||||
* @since 5.7.0
|
||||
*/
|
||||
function wp_sensitive_page_meta() {
|
||||
function wp_strict_cross_origin_referrer() {
|
||||
?>
|
||||
<meta name='robots' content='noindex,noarchive' />
|
||||
<meta name='referrer' content='strict-origin-when-cross-origin' />
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user