Codex tools: Log in
Contents |
The wp_title filter is used to filter the title of the page. This filters 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, 3 ) ?>
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.
Using the wp_title filter with a custom callback function is the preferred way of changing the title tag and now required for all themes. The common bad practice of putting <title><?php bloginfo('name'); ?> « <?php wp_title(); ?></title> directly into the header.php file leaves no way for a plugin to modify the whole title. An example of a custom filter function themes should use to change the title is provided here.