12

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

6
  • Thats the way to do it, using a custom link. Not hard coded into any file as you can change it anytime. Commented Aug 10, 2015 at 17:04
  • @BradDalton Hmm. Now I'm wondering how to get WPML to translate the link then! Commented Aug 10, 2015 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. Commented Aug 11, 2015 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. Commented Aug 11, 2015 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). Commented Aug 11, 2015 at 10:20

1 Answer 1

33

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

4
  • 7
    "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. Commented Feb 3, 2017 at 13:00
  • 4
    And don't forget to add 'has_archive' => true when creating your CPT.
    – pjehan
    Commented Sep 5, 2018 at 14:38
  • 2
    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) Commented Oct 5, 2018 at 13:25
  • still not there. Also tested has_archive => "my_special_rewrite_string". Can see other CPTs in "Archives" but not mine. Will use User Link as workaround :/
    – Fanky
    Commented Oct 29, 2021 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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