hide it

Drupal - Hide a block for a specific node type

, on March 16, 2008

I needed to hide a block for a certain node type on a drupal driven website so i found this snippet on drupal.org. I will post it here for my future needs.

Paste this in "Page specific visibility settings" tab on the block you want to hide. Select "Show if the following PHP code returns TRUE (PHP-mode, experts only)." first.

<?php
$match = TRUE;
$types = array('story' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  if (isset($types[$type])) {
    $match = FALSE;
  }
}
return $match;
?>
Anonymous's picture
Thanks, Works a treat

Anonymous's picture
in drupal 6... I switched the last "$match = FALSE;" to be "$match=TRUE;" And I can't get it to work the way I want. in fact, even with it as FALSE, it shows up on EVERY page. Any thoughts? Thanks

Anonymous's picture
Hi, What if there is an url alias? How can you get the nid if it is not in the url? David

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.