Hello. First I am going to suggest why this might be failing. Then I’m going to make a suggestion that you try it another way.
First the problem you are having is that you are asking
if ( is_page() && is_page($item->object_id) ) {
is_page()
, is_category()
, and most similar template related function “is_” functions have to do with what page you are ON (i.e. what page is being displayed).
However, the object_id
of the home link in the menu appears to be the same as the menu id it is given (unlike posts/pages/categories where the object_id is the post/page id or the taxonomy_id). So in your case that home link in the menu is being assigned a value of ‘4’ (this is mostly conjecture). So is it possible that the “home page” has an id of “4” and is a page? Or more coincidentally the page you assigned to the home page (assuming you are using a static home page)?
Though this wouldn’t explain the fact that it is saying yes to both the page and the category condition. But I would definitely look at the id’s of the pages and categories in the install for a clue.
However, since you seem to just be attempting to mark the current menu item as being the current page you are on I am going to ask if you have tried using wp_nav_menu()
?
http://codex.wordpress.org/Function_Reference/register_nav_menu
http://codex.wordpress.org/Function_Reference/wp_nav_menu
It automatically outputs classes indicating the current menu item for the current page being viewed as well as other useful stuff if you are doing drop down or heirarchal menus. Personally I love it.
Optionally you can register the menu with WordPress explicitly:
register_nav_menu('hd_menu', 'Masthead Menu'); //primary site nav
Then in the template where you want to output it (once you’ve made it and assigned it in the Admin menu screen).
wp_nav_menu( array(
'theme_location' => 'hd_menu',
'container' => false,
'container_class' => false,
'menu_id' => 'hd_menu_list',
'sort_column' => 'menu_order',
'depth' => '4',
'fallback_cb' => 'kstWpNavMenuFallbackCb'
) );
And even if you don’t want to use wp_nav_menu(), you could just make the area where the menu is a widget area, add the menu to a widget in that area, and you get the same convenient markup and css classes.
You can see an example and check out the markup and css here on my demo site. The masthead is using wp_nav_menu() and the footer in the lower left is a widget area with a menu it.
http://beingzoe.com/zui/wordpress/kitchen_sink/kitchen_sink_html5_base_demo/
Hope that helps. I would love to know why that was happening with your original code though. Very strange and frustrating I am sure.