11

I need a way to hide a content type on the node add page, or better yet, make two separated node add pages that separate my content types. I'm on Drupal 7 and have four different content types. I would like three of them to be on the default node add page and the fourth to be separate. How would I do this? Thanks

0

4 Answers 4

12

Two possibilities:

  • admin/structure/menu/manage/navigation move/delete menu item that you don't want.
  • Cleanest way: use roles and permissions. If the user can't create a content type the link will not appear in any menu.
3
  • Thanks for your answer. Your first possible way is the one I would use because I still need users to be able to create nodes of my fourth content type. I just need it separated from the other three.
    – oobie11
    Commented Dec 16, 2011 at 10:31
  • Ok so just move the menu item in another menu or hide it and create another one this the same menu link (node/add/<your_content_type>)
    – nourcy
    Commented Dec 16, 2011 at 11:24
  • This is the best answer.
    – Christia
    Commented Apr 16, 2018 at 21:42
4

Put this in a custom module:

function yourcustommodule_menu_alter(&$items) {
  if (isset($items['node/add/your-content-type'])) {
    $items['node/add/your-content-type']['type'] = MENU_DEFAULT_LOCAL_TASK;
  }
}
1
  • 2
    MENU_DEFAULT_LOCAL_TASK converts the links into tabs. I have used MENU_CALLBACK instead.
    – Freeman
    Commented Jul 24, 2013 at 10:43
3

UPDATE

MENU_CALLBACK, as suggested in other answers, didn't work for me here. They still appear on the node/add page.

This code worked:

function MYMODULE_menu_alter(&$items) {
  if (isset($items['node/add/your-content-type'])) {
    unset($items['node/add/your-content-type']);
  }
}

Of course, it assumes you want to disable (not hide) the node/add link for that type.


ORIGINAL ANSWER

The node/add page is provided by the Node module. You might be able to do what you want by disabling the menu item in the Navigation menu, according to this post: http://data.agaric.com/disabling-or-moving-nodeaddcontent-type-links-from-beneath-add-content-navigation-menu-also-removes

It's a bit of a bug, so it might not be a reliable way to do it. Personally, I'd create a custom version of the node/add page in a module by copying the existing one and making my specific modifications. Then I would use hook_menu_alter to make node/add go to my version.

You might be able to replace it with a view or panel instead (with Page Manager), but I haven't tried this, and you'd probably lose the automation.

3
  • Thanks! Where is the node/add page located in for me to copy? And how would you suggest printing out the different content types?
    – oobie11
    Commented Dec 16, 2011 at 10:34
  • It should be in node.pages.inc. If you need the other types to show up as you create them and don't have a static list, do it in code. Commented Dec 16, 2011 at 20:58
  • Self-follow-up: I don't like my own answer from 4.5 years ago. Use one of the ones above :) Commented May 28, 2015 at 11:05
0

There is now a best solution in contrib (Drupal 7 and modern Drupal) that makes it easy again, providing a separate menu to power a replacement "Add content" page:

https://www.drupal.org/project/custom_add_content

(Glad i found that module as i was about to make the equivalent, since it was my fault it got difficult— as wizonesolutions pointed to, i reported the bug that disconnected the menu from the page)

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.