Dynamic menu with custom post types

So I think you are asking how to dynamically highlight the tab of the page you are currently on. I did something like this on my recent website project because I needed to highlight a certain tab when I was on a custom post type.

Here is some code you could use for your website:

function custom_tab_highlighting() { 
    global $post;
    ?>
    <ul>
    <?php if( is_front_page() || is_page('my-page') || is_post_type_archive('my-custom') || is_page('blog') ) { ?>
        <li class="current_page_item">
            <a href="https://wordpress.stackexchange.com/questions/40947/<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php } else { ?>
        <li class="tab">
            <a href="https://wordpress.stackexchange.com/questions/40947/<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php } ?>
    </ul>
<?php
}

This is really a much cleaner way to create a menu by using the “||” symbol. Although I’m guessing you are going to want to list all your pages out whether or not you are on that page… I’ll leave you to code that functionality. Try using a for or foreach loop to list all the pages.

Hope this helps.

If you were using WordPress’s wp_list_pages function then you could use something like this to highlight a tab when you were on a certain post_type:

// this highlights the "Sermons" tab when I'm on a post type of "sermon_post"
// just set the get_post_type and $page->ID values accordingly
function my_page_css_class( $css_class, $page ) {
    global $post;
    if ( get_post_type() == 'sermon_post' && $page->ID == '11' ) {
        $css_class[] = 'current_page_item';
    }
    return $css_class;
}
add_filter( 'page_css_class', 'my_page_css_class', 10, 2 );