Drupal 7: Hide a Block for a certain content type

Per default block configuration you can only decide to show a block for certain content types, the other way around requires a little bit of PHP. The following snippet hides a block on nodes of type article and blog:

  // Only show if $match is true
  $match = true;

  // Which node types to NOT show block
  $types = array('article', 'blog');

  // Match current node type with array of types
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load($nid);
    $type = $node->type;
    if(in_array($type, $types)) {$match=false;}
  return $match;

Leave a Reply