Function to Change Page Title In WordPress

I am using the below function to change the page title in wordpress. It is working on a single page (page.php), but is not working on my static home page or individual posts (single.php).

What do I need to change in order to make this work across the entire site?

<?php


function wpse46249_filter_wp_title( $title ) {

    $some_custom_title_content = 'This is added to title';

    $custom_title = $title . $some_custom_title_content;

    return $custom_title;
}
add_filter( 'wp_title', 'wpse46249_filter_wp_title' );
?>

Related posts

Leave a Reply

1 comment

  1. function wpse46249_filter_wp_title( $title ) {
    
        $some_custom_title_content = 'This is added to title';
    
        $custom_title = $title . $some_custom_title_content;
    
        return $custom_title;
    }
    add_filter( 'the_title', 'wpse46249_filter_wp_title' );
    

    please note the title is saved in wp_posts table. The filter you used above will change all new posts titles being saved. This filter just modifys the title after pulling it from the db and doesn’t actually change the db value.

    Also will only work on pages where the_title() is called.