Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "Title Tag"

m (Resources)
m (Related: added link to filter for title text)
 
(3 intermediate revisions by 2 users not shown)
Line 32: Line 32:
 
* [http://generatewp.com/theme-support/ WordPress Theme Support Generator]
 
* [http://generatewp.com/theme-support/ WordPress Theme Support Generator]
 
* [https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/ Make.WordPress.org announcement of title-tag]
 
* [https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/ Make.WordPress.org announcement of title-tag]
  +
* [https://make.wordpress.org/themes/2015/08/25/title-tag-support-now-required/ Theme Review Team: Title tag support now required]
* [http://cloudspier.com/exploring-title_tag-theme-feature/ Exploring title_tag theme feature]
+
* [https://bravokeyl.com/exploring-title-tag-theme-feature/ Exploring title_tag theme feature]
   
 
== Related ==
 
== Related ==
 
{{Theme Support}}
 
{{Theme Support}}
  +
  +
Filter the title tag text with wp_title: https://developer.wordpress.org/reference/hooks/wp_title/
   
 
[[Category:Advanced Topics]]
 
[[Category:Advanced Topics]]

Latest revision as of 21:08, 7 December 2017

Title Tag is a theme feature, first introduced in Version 4.1. This feature allows themes to add document title tag to HTML <head>.

Adding Theme Support

Since Version 4.1, themes should use add_theme_support() in the functions.php file in order to support title tag, like so:

add_theme_support( 'title-tag' );

Backwards Compatibility

To add backwards compatibility for older versions, use the following code:

<?php
if ( ! function_exists( '_wp_render_title_tag' ) ) {
	function theme_slug_render_title() {
?>
<title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
	}
	add_action( 'wp_head', 'theme_slug_render_title' );
}
?>

Resources

Related

Theme Support: add_theme_support(), remove_theme_support(), current_theme_supports()
Theme Features: sidebar, menus, post-formats, title-tag, custom-background, custom-header, custom-logo, post-thumbnails, automatic-feed-links, html5, editor-style, content_width

Filter the title tag text with wp_title: https://developer.wordpress.org/reference/hooks/wp_title/