Is there a way (besides adding a Custom Link) to add a custom post type archive to a menu in WordPress? If it's added using a custom link (e.g. /cpt-archive-slug/), WordPress does not apply classes like current-menu-item to the list element, which presents challenges when styling the menu.

If the custom link contains the entire URL (e.g. http://site.com/cpt-archive-slug/), those classes are added. However, that's probably not a 'best practice'.

link|improve this question

feedback

5 Answers

up vote 3 down vote accepted

your best opption is custom link with full url as Custom post types archives are different form taxonomy based archives (categories,tags,any custom taxonomy) and date based archives which have there own archive slug.

link|improve this answer
feedback

You can create a Page and then apply a custom archive template to it. I create and use archive-{post-type}.php fo the template name just like you would for the default archive, I just manually apply it to the Page.

If you do this, I'd recommend setting your CPT to has_archive='false' to avoid permalink collisions, regardless just make sure your Page has a different permalink slug than your CPT archive slug is set to.

link|improve this answer
feedback

I ran into the same exact problem, and found this solution:

// $menu is the menu as a string 
if ( check if youa re on the page you are looking for )
    $menu = str_replace( '<li class="menu-item"><a href="http://bla.com/bloop/">', '<li class="current-menu-item menu-item"><a href="http://bla.com/bloop/">'>, $menu );  

Source: http://www.wptavern.com/forum/plugins-hacks/2169-current-page-custom-post-type-archive.html

link|improve this answer
feedback

I think I'd have to create a new "parent" post-type, so the custom-post-type I want to show becomes a "child", and that parent WILL be listed in the menu.

This should be an option. Creating a dummy parent just for getting it listed in the menu is too much work.

I'd like a way to do it from the template, or functions, so I don't have to do it in each menu settings for each site in my multisite installation.

link|improve this answer
I meant, the custom-post-type posts I wanted to show in the menu will be the only sub-type of the new-created parent, and I hope it gets listed under the parent in the menu settings. – sergio Sep 27 '11 at 15:06
feedback

I Found this answer when searching for a similar issue. I just copied the code into my finctions.php file and it worked right out of the box :) hope it helps!

Dynamic navigation for custom post type (pages)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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