7

I've created a Custom Post type (project) and it works perfectly. I have a custom archive page (archive-project.php), and that works great, too, but what's the best way to add a link to that custom post archive in the site's primary menu?

I've created a Custom Link (see below), but is there a better way that isn't so hard coded?

enter image description here

  • Thats the way to do it, using a custom link. Not hard coded into any file as you can change it anytime. – Brad Dalton Aug 10 '15 at 17:04
  • @BradDalton Hmm. Now I'm wondering how to get WPML to translate the link then! – Django Reinhardt Aug 10 '15 at 17:09
  • 1
    @ialocin What a completely unhelpful comment. If you think there's other way to do it, post links or an answer. – Django Reinhardt Aug 11 '15 at 9:58
  • I beg to differ, I was just trying to hint you to it and thats what comments are there for, make remark not worthy of an answer, but lets just agree to disagree. WPML is - IIRC - able to translate archive slugs, so if you are able to add archives to the menu, then they should be translated. Not sure - any more, haven't used it in quite some time - how WPML exactly handles menu translation, but it should definitely be in its scope. – Nicolai Aug 11 '15 at 10:10
  • @ialocin I see. There are two questions here. One is how to add a custom post archive to a navigation menu, and the other is how to get WPML to translate that link. The first question is what you were referring to in you reply, and that question still requires an answer (and is on topic for this SE). – Django Reinhardt Aug 11 '15 at 10:20
25

You can use a built in function of the menu editor for this. Go to your Custom Post Type in the Menu editor, click the "view all" tab and the first item you see is a link to the CPT archive page.

add custom post type archive to menu

In case your CPT does not appear in the Menu editor please check whether your CPT has archives enabled ('has_archive' => true in the register_post_type-arguments).

When you are sure that archives are enabled and your CPT is still not visible you can reveal it through the Screen Options menu at the top of the screen (thanks, Nathan Hornby).

reveal Custom Post Types via Screen Options menu

  • 3
    "Go to your Custom Post Type in the Menu editor". FYI to others, you need to manually show individual custom post types on the 'Menus' page using the 'Screen options' fly-out; otherwise they won't show up there. – Nathan Hornby Feb 3 '17 at 13:00
  • 2
    And don't forget to add 'has_archive' => true when creating your CPT. – pjehan Sep 5 '18 at 14:38
  • 1
    A strange behaviour I just discovered ist that the UI is not available, if no posts in for this type are available (v4.9.8). You need to publish a post to be able to add the archive to menus (maybe an odd use case anyway) – Julian F. Weinert Oct 5 '18 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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