apply_filters( 'wp_title', string $title, string $sep, string $seplocation )

Filters the text of the page title.


Description Description


Parameters Parameters

$title

(string) Page title.

$sep

(string) Title separator.

$seplocation

(string) Location of the separator ('left' or 'right').


Top ↑

Source Source

File: wp-includes/general-template.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

More Information More Information

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:

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.



Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Drew Jaynes

    Basic Example

    In header.php:

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

    In functions.php:

    /**
     * Creates a nicely formatted and more specific title element text
     * for output in head of document, based on current view.
     *
     * @param string $title Default title text for current view.
     * @param string $sep   Optional separator.
     * @return string Filtered title.
     */
    function wpdocs_filter_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', 'wpdocs_filter_wp_title', 10, 2 );
    
  2. Skip to note 2 content
    Contributed by Andrew Klimek

    wp_title is being deprecated, see https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/

    Please use:

    pre_get_document_title – short-circuits wp_get_document_title() if it returns anything other than an empty value.
    document_title_separator – filters the separator between title parts.
    document_title_parts – filters the parts that make up the document title, passed in an associative array.

  3. Skip to note 3 content
    Contributed by acuvic

    Just for information, wp_title has been reinstated:
    UPDATE 12 November – wp_title has been reinstated until alternative usages have been identified and a path forward for them defined.

    Reference link as originally given by Andrew Klimek above https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/

You must log in before being able to contribute a note or feedback.