• Resolved Agus Suhanto

    (@suhanto)


    I was trying to apply the_title filter to change a page title. But, as it changed, the menu title (WordPress 3.0) that corresponds to that page is also changed. And currently I still don’t know how to differentiate the title when it is rendered in page title or in menu title.

    Any suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Agus Suhanto

    (@suhanto)

    ah, I just knew the answer…

    the_title() filter has additional parameter = $id. I can compare the value of $id parameter with $post->ID. Although the title of the page is the same with the title of its corresponding menu, the ID is different. Hence I can differentiate the page title and the menu title and apply the filter accordingly.

    For instance (because people require examples.. like myself)

    add_filter('the_title','add_field');
    
    function add_field($title)
    {
    global $id;
    if (in_category('1') && $id) {
    	global $post;
    	$key = "location";
    	$data = get_post_meta($post->ID,$key,true);
    global $wp_query;
    //print_r($wp_query);
    
    	return $title."</a><br /><div style='font-size:10px;line-height:120%;padding-top:3px'>".$data."</div><a>";
    
        }
    else {
    	return $title;	
    
    }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why the_title() filter is also applied in menu title?’ is closed to new replies.