Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#40005 closed defect (bug) (worksforme)

Add some customization ability to WP_TITLE

Reported by: tazotodua's profile tazotodua Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: close
Focuses: Cc:


by default, _wp_render_title_tag function is hooked in wp_head, 1 (in wp-includes\general-template.php):

function _wp_render_title_tag() {
    echo '<title>' . wp_get_document_title() . '</title>' . "\n";

it leaves us no chance to modify, filter ... the title... (although wp_get_document_title has some hooks, but not full ability to modify full title thought),
it explicitly echoes the title.... instead, we should have filters,like this:

function _wp_render_title_tag() {
    $title =  '<title>' .  apply_filters('render_title_tag', wp_get_document_title() ) . '</title>' . "\n";
    $echo = apply_filters('echo_render_title_tag', true);
    if ($echo) {     echo $title;    }
    else {     return $title;    }


Change History (5)

#1 @swissspidy
7 years ago

  • Component changed from General to Themes
  • Keywords close added

wp_get_document_title() has some hooks, but not full ability to modify full title thought

That function has the pre_get_document_title filter which allows you to short-circuit the complete output.

See also and

#2 follow-up: @tazotodua
7 years ago

that fitler has to fully replace title. It was good, if there was ability to :
1) get title after that function defines title (who know, maybe I only want to change small part of title, after finally declaring the title)
2) ON/OFF automatic echo output.

however, thanks./

#3 in reply to: ↑ 2 @SergeyBiryukov
7 years ago

Replying to tazotodua:

that fitler has to fully replace title.

Not necessarily, you could do something like this:

function wp40005_filter_document_title( $title ) {
	remove_filter( 'pre_get_document_title', __FUNCTION__ );

	$title = wp_get_document_title();

	add_filter( 'pre_get_document_title', __FUNCTION__ );

	// Change the output
	// $title = ...

	return $title;
add_filter( 'pre_get_document_title', 'wp40005_filter_document_title' );

#4 @tazotodua
7 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

#5 @netweb
7 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.