Drupal 7

Say I have a custom element being rendered out on my page.tpl.php (say it's named $custom_element in the below example), but this is also showing up on the Node Edit page because I want this user to not use the admin theme to edit Nodes but just same theme the front end is using to edit Nodes.

What hook do I use to hide this element when the user is editing the node? What's the best approach in this?

My template.php file

function mytheme_preprocess_page(&$vars, $hook) {
  if (in_array('page__mypagetype', $vars['theme_hook_suggestions'])) {
    $vars['custom_element'] = my_custom_element();

Sorry if this doesn't make sense. I'm not sure I'm using the proper wording. Basically trying to figure out how to say "Drupal, while the user in logged in and editing these nodes, please don't show this element on the node edit page since it's printed in the page.tpl.php".

I know this can be done by creating a page--node--edit.tpl.php page. But isn't there a way to do this via a hook in the template.php?

1 Answer 1


As fast solution, verify the value returned from arg(2) is different from 'edit'.

   function mytheme_preprocess_page(&$vars, $hook) {
      if (in_array('page__mypagetype', $vars['theme_hook_suggestions']) && arg(2) != 'edit) {
        $vars['custom_element'] = my_custom_element();
  • Ah I see, so you're just pulling the args from the url itself. Nice! Great idea. That's a ton.
    – tdm
    Nov 21, 2014 at 17:01

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.