Make WordPress Core

Changeset 51019


Ignore:
Timestamp:
05/25/2021 11:42:15 PM (3 years ago)
Author:
desrosj
Message:

Formatting: Introduce the document_title filter.

In wp_get_document_title(), the returned value is currently passed directly through wptexturize(), convert_chars(), and capital_P_dangit(), and is done so after the document_title_parts` filter is run.

This makes it impossible to fully control the output of wp_get_document_title() and is inconsistent with how other similar text is processed with these functions.

This commit introduces the document_title filter, which is run immediately before returning the results of the wp_get_document_title() function and moves the three formatting functions mentioned above to the new filter hook. This allows developers to further modify the title after being prepared by WordPress, or to modify the functions hooked to this filter as they wish.

Props dragunoff, jeremyfelt, paaggeli, audrasjb.
Fixes #51643.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

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

    r51003 r51019  
    132132
    133133// Format strings for display.
    134 foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) {
     134foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'document_title', 'widget_title' ) as $filter ) {
    135135    add_filter( $filter, 'wptexturize' );
    136136    add_filter( $filter, 'convert_chars' );
     
    139139
    140140// Format WordPress.
    141 foreach ( array( 'the_content', 'the_title', 'wp_title' ) as $filter ) {
     141foreach ( array( 'the_content', 'the_title', 'wp_title', 'document_title' ) as $filter ) {
    142142    add_filter( $filter, 'capital_P_dangit', 11 );
    143143}
  • trunk/src/wp-includes/general-template.php

    r50912 r51019  
    12391239
    12401240    $title = implode( " $sep ", array_filter( $title ) );
    1241     $title = wptexturize( $title );
    1242     $title = convert_chars( $title );
    1243     $title = esc_html( $title );
    1244     $title = capital_P_dangit( $title );
     1241
     1242    /**
     1243     * Filters the document title.
     1244     *
     1245     * @since 5.8.0
     1246     *
     1247     * @param string $title Document title.
     1248     */
     1249    $title = apply_filters( 'document_title', $title );
    12451250
    12461251    return $title;
Note: See TracChangeset for help on using the changeset viewer.