In this Drupal Development tutorial I will show how one (perhaps you) can hide a block for nodes on specific taxonomy. But before we dig in, lets look to an example.

Let's say you are displaying Google Adsense ads on your Drupal website or blog, ads are displayed by using blocks. Everyhting fine. But then you realize, there are some pages (nodes) you are not willing to show Google Ads. For example you are doing an affiliate marketing, and you have specific taxonomy, in which all affiliate marketing nodes are tagged in. 

So how to hide that block containing Google Adsense?

Google Adsense's block in article.

In above image you can see Google Adsense being displayed in articles for my blog.

So, but I do affiliate marketing as well, and there are few articles on my blog I down want my readers been distracted and taken away by Google Adsense.

So what's the solution?

In previous Drupal 6 version I used to use a php code display or hide blocks based on taxonomies. The thing is - in Drupal 7 I have found this doesn't work I want (if you have a working example - please, drop a comment).

So I started to look into existing Drupal Modules, that might help to achieve behaviour I'm looking for. And, the thing is - after a quick search I have foud one useful module, what does what I need it to do. 

Meet the Block Visibilty by Term module

Block Visibility by Term extends the block visibility interface in Drupal 7 and allows the user to control block visibility based on the terms that a node is tagged with. For each block, taxonomy terms can be selected. If the displayed node is tagged with at least one of those terms, the block will be visible; if not, it will be hidden.

Add this module to your drupal site, and now by configuring your block you should see a following scene

Block Visibility Settings for Drupal

Now, by checking specific taxonomy terms we can configure for which terms to display block, unfortunetalty this is not working vice verse.

So, this is not a complete solution, but it's rather temporary fix, on the other hand, as I like to think - keep it simple - Drupal as I do believe is one of the most powerful CMS in the industry, but still the main reason is to have visitors on site, right?

Anyway, here is the page with Block Terms module on action:

Hidden Adsense block on Drupal articles

In Conclusion

There are times we need to achieve some specific behaviour  - we can spend hours and days to write some custom codes, but there are times and cases, when we can achieve that results by using already deployed modules. This is one of the reasons I love Drupal, it's agile - you can do both ways - work with existing modules or write your own.

And, yes with help of above mentioned module, we can hide Google Adsense block for specific terms (or rather display it on specific terms).

Drop a comment and/or find more what I have to say on Drupal Development