the_title filter applying to menu items

Use in_the_loop() conditional tag to make sure you are modifying the title inside the Loop and to prevent the hook changing titles somewhere else:

function customize_wishlist_title( $title ){
    $current_user = wp_get_current_user();
    $loggeduser = $current_user->user_login;
    // give attention to the following condition:
    if ( is_page( 258 ) && in_the_loop() ) {
        $title="<span class="username">".$loggeduser.'\'s'.'</span>'.'&nbsp;'.'<span>Wishlist</span>';
    } 
    return $title;
}
add_filter('the_title','customize_wishlist_title', 10, 2);

See in_the_loop() reference.

Leave a Comment