Friday, 15 November 2013

Hide View/Edit node tabs per content type in Drupal 7

What:

Drupal 7

Problem:

You need to hide View/Edit node tabs, but only for selected content type.

Solution:

Edit your template.php file and insert following code:

/**
 * Remove tabs on article content type
 */
function my_template_preprocess_page(&$variables, $hook) {
       if (!empty($variables['node']) && $variables['node']->type == 'article') {
            my_template_removetabs('Edit', $variables);
       }
}

function my_template_removetabs($label, &$vars) {
        $vars['primary_local_tasks'] = '';
}

Replace my_template with actual name of your template.

Now "Clear all caches" and test.

Note: node/edit path will be still available.

No comments:

Post a Comment