#40005 closed defect (bug) (worksforme)
Add some customization ability to WP_TITLE
Reported by: | tazotodua | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | close |
Focuses: | Cc: |
Description
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)
#2
follow-up:
↓ 3
@
8 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
@
8 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' );
Note: See
TracTickets for help on using
tickets.
That function has the
pre_get_document_title
filter which allows you to short-circuit the complete output.See also https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/ and https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/