Make WordPress Core


Ignore:
Timestamp:
01/21/2021 01:35:16 AM (4 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r49904 r49992  
    231231// Email filters.
    232232add_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
     233
     234// Robots filters.
     235add_filter( 'wp_robots', 'wp_robots_noindex' );
    233236
    234237// Mark site as no longer fresh.
     
    292295add_action( 'wp_head', 'locale_stylesheet' );
    293296add_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 );
    294 add_action( 'wp_head', 'noindex', 1 );
     297add_action( 'wp_head', 'wp_robots', 1 );
    295298add_action( 'wp_head', 'print_emoji_detection_script', 7 );
    296299add_action( 'wp_head', 'wp_print_styles', 8 );
     
    312315
    313316if ( isset( $_GET['replytocom'] ) ) {
    314     add_action( 'wp_head', 'wp_no_robots' );
     317    add_filter( 'wp_robots', 'wp_robots_no_robots' );
    315318}
    316319
    317320// Login actions.
     321add_action( 'login_head', 'wp_robots', 1 );
    318322add_filter( 'login_head', 'wp_resource_hints', 8 );
    319323add_action( 'login_head', 'wp_print_head_scripts', 9 );
     
    586590add_action( 'embed_head', 'wp_print_head_scripts', 20 );
    587591add_action( 'embed_head', 'wp_print_styles', 20 );
    588 add_action( 'embed_head', 'wp_no_robots' );
     592add_action( 'embed_head', 'wp_robots' );
    589593add_action( 'embed_head', 'rel_canonical' );
    590594add_action( 'embed_head', 'locale_stylesheet', 30 );
     
    597601add_action( 'embed_footer', 'wp_print_footer_scripts', 20 );
    598602
     603add_filter( 'wp_robots', 'wp_embed_no_robots' );
    599604add_filter( 'excerpt_more', 'wp_embed_excerpt_more', 20 );
    600605add_filter( 'the_excerpt_embed', 'wptexturize' );
Note: See TracChangeset for help on using the changeset viewer.