Drupal 7 – Disable the node view URL for some content types

Sometimes the content types we created are only used in Views. We don’t want to have the node view page for those content. The following solution would turn those unwanted node view pages to 404 not found.

Create a custom module and implement the hook_node_view() as follow.

function <module>_node_view($node, $view_mode, $langcode) {
  if ($node->type == '<content-type>' && $view_mode == 'full' && !user_access('edit any <content_type> content')) {


Replace the <content-type> with the content type machine name. Enable the module and clear the cache. You will find that those node view pages are not found but the edit tab is still valid if the logged in user has the proper permission. You can also restrict the access by a different permission.

Done =)

Reference: StackOveflow – Display a node in Views, but disable the node page


2 thoughts on “Drupal 7 – Disable the node view URL for some content types”

  1. Very good idea.

    I’m using to redirect on my custom view instead of using 404:
    drupal_goto(‘real url’);

    (you get an useless parenthesis 😉

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.