1

I'm having a bit of an issue changing the title on a custom page. Most the time the standard code works, but for whatever reason on certain WordPress setups I am unable to change the default title.

What usually works, but is not working in this situation:

function customtitle(){
    return "custom title";
}
add_filter('wp_title', 'customtitle', 10);

I'm also aware of the issues with changing custom titles and the yoast plugin. On the current WordPress setup I'm working with yoast is not installed. I wanted to know if there was another hook or method that I can override the title over the current default title.

1 Answer 1

2

This is most likely due to difference in your theme's support. Some themes render the title by using the wp_title filter, some by using pre_get_document_title. If your theme has this line in its functions.php file:

add_theme_support('title-tag');

Then you need to use the pre_get_document_title filter, as follows:

add_filter('pre_get_document_title', 'my_title');
function my_title() {
    return 'Some title';
}

This is for the newer versions of WordPress. The old installations might be still using the legacy wp_title() function, which you already mentioned in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.