Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to change just wordpress post title but not menu items.

add_filter('the_title', 'wordpress_title');
function wordpress_title(){
  return 'New title';
}

enter image description here

share|improve this question
Use in_the_loop() conditional check. – amit Sep 7 '12 at 8:00

3 Answers

add_filter('the_title', 'wordpress_title');
function wordpress_title($title){

    //Return new title if called inside loop
    if ( in_the_loop() )
        return 'New title';

    //Else return regular   
    return $title;

}

Have you tried the in_the_loop() conditional check to return new title only if called inside loop. That means nav menu's will not get affected.

share|improve this answer

If you're using custom nav menus, you can do this entirely without code. Go to Appearance -> Menus and change the "Navigation Label" of each menu item you want to be different.

share|improve this answer
<?php add_filter('the_title', function($title) { return '<b>'. $title. '</b>';}) ?> 
share|improve this answer
Menu items ant post name now bold. I need change just post title (<h2>) and not menu items. – qq3 Oct 8 '11 at 13:49
Modify the theme, and not the filter. – keatch May 10 '12 at 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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