getdave / Tanlinell

Boilerplate Wordpress theme for rapid development of new WP themes. Based on the great work of the _s ("Underscore") theme.
GNU General Public License v2.0
6 stars 2 forks source link

Add function to add current_page_item to menus #189

Closed getdave closed 11 years ago

getdave commented 11 years ago

Make sure that current_page_item class is added to menus. Particularly useful for create sub navigation for a CPT because be default WP doesn't add the current class to wp_list_pages() output when used with CPT.

/**
 * Add "current" Page Class to Menus
 * read more at:
 * http://wordpress.stackexchange.com/questions/6333/adding-class-current-page-item-for-custom-post-type-menu
 * 
 */
function tanlinell_page_css_class( $css_class, $page ) {
    global $post;
    if ( $post->ID == $page->ID ) {
        $css_class[] = 'current_page_item';
    }
    return $css_class;
}
add_filter( 'page_css_class', 'tanlinell_page_css_class', 10, 2 );
neilberry001 commented 11 years ago

Addressed via : 6222d5c1c09c1f2255e0c32b74fefdd81aaed1cb

Update has been made to burfield-customisations as more appropriate location could not be found @getdave