In my child theme’s functions.php file, I’m trying to change a page’s title tag:

function custom_title() {
    return "Page Title";
}
add_filter( 'wp_head', 'custom_title', 9999 );

The code above is not changing the page’s default title. What am I doing wrong?

1
1

Check this out

function custom_title($title_parts) {
    $title_parts['title'] = "Page Title";
    return $title_parts;
}
add_filter( 'document_title_parts', 'custom_title' );

In custom_title, $title_parts contains ‘title’, ‘page’ (the pagination), ‘tagline’ (the slogan you specified) and ‘site’. Set “title” the way you like.

Leave a Reply

Your email address will not be published. Required fields are marked *