Hide block for certain content type in Drupal 6

Hide block for certain content type in Drupal 6

Quite often you want to hide or show a block only for a specific content type in Drupal. There is a quite simple hack you can do for achieving that! This is for Drupal 6, in Drupal 7 there is a core function that lets you do the same. Use this code to hide a block for a certain content type in drupal 6:
$match = TRUE;
$types = array(‘library’ => 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;
if (drupal_is_front_page()) {
$match = FALSE;
return $match;

When editing a block, paste this in the box on the bottom of the page and chose “show only if the following php-code returns ‘true’.” Then the block will show on every content type except the “library”-one, and neither on the frontpage. Of course you can change the “library” to whatever content type you want. As you see, a little lower in the code you find this: if (drupal_is_front_page()), that means that we hide it also on the frontpage. Remove that line and the two under it if you don’t want to use that function.

You like posts about Drupal? Then, read also my post about how to create quicktab blocks with cck fields inside.

  • Andreas

    Hi this doesn’t work? do you have an example of code where the block is only visible for content type X

    • Hi! I think it works? just change the “library” to the content type you have. And if you change the first “$match = TRUE;” to “$match = FALSE;” and the second one the other way around (FALSE to TRUE), this code should work the other way (show the block only on the content type you chose, in this case “library”). Good luck! :)

Download new responsive WordPress template

New responsive WordPress template with big call-to-action-areas, header-slider and different color-themes. It is built on Bootstrap and named Strap Them Boots On. Read more and download!

The one writing here:

Important information

This is the search engine optimization (SEO) and web tactics webiste/blog for Jonathan Björkskog, working at and co-owning Genero Digital Agency, a digital advertising agency based in Helsinki, Finland. If you searched for my Swedish blog, you find it here: jonathanbjorkskog.se.

That's one of my passions.

If you were searching for the other one, kitesurfing, you should check out my kitesurfing blog instead.

Follow on Facebook

Head over to the wall and send me all your questions about Facebook, SEO, or any other awesome topic on the internet!

Premium SEO-Plugin

Brian D. Hawkins about SEOPressor:

It’s almost as if SEOPressor took those features from my checklist. I guess I’m old school but I have a checklist that I use when writing new posts. It’s pretty cool that SEOPressor helps automate some of those tasks and the check/remind feature is very nice. As usual I love your presentation.


Click Here to Download
Read my SEOPressor review