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

Plugin API/Filter Reference/wp title


The wp_title filter is used to filter the title of the page (called with wp_title()). This filters the text appearing in the HTML <title> tag (sometimes called the "title tag" or "meta title"), not the post, page, or category title.

A plugin (or theme) can register as a content filter with the code:

<?php add_filter( 'wp_title', 'filter_function_name', 10, 2 ) ?>

Where 'filter_function_name' is the function WordPress should call when the content is being retrieved. Note that the filter function must return the content after it is finished processing, or the title will be blank and other plugins also filtering the content may generate errors.

filter_function_name should be unique function name. It cannot match any other function name already declared.


(string) (required) Title of the page.
Default: None
(string) (optional) How to separate the various items within the page title. Default is '»'.
Default: None
(string) (optional) Direction to display title, 'right'.
Default: None



<title><?php wp_title('|', true, 'right'); ?></title>


 * Creates a nicely formatted and more specific title element text
 * for output in head of document, based on current view.
 * @since Twenty Twelve 1.0
 * @param string $title Default title text for current view.
 * @param string $sep Optional separator.
 * @return string Filtered title.
function twentytwelve_wp_title( $title, $sep ) {
	global $paged, $page;

	if ( is_feed() )
		return $title;

	// Add the site name.
	$title .= get_bloginfo( 'name' );

	// Add the site description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		$title = "$title $sep $site_description";

	// Add a page number if necessary.
	if ( $paged >= 2 || $page >= 2 )
		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );

	return $title;
add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );

See Also