Make WordPress Core


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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.