How To Hide Drupal Block For Nodes In Specific Taxonomy - Example With Google Adsense

<p>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.</p><p>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.&nbsp;</p><h2>So how to hide that block containing Google Adsense?</h2><p><img src="http://www.reinisfischer.com/sites/default/files/drupalads.jpg&quot; alt="Google Adsense For Drupal" title="Google Adsense For Drupal" width="948" height="562"></p><p><em>Google Adsense's block in article.</em></p><p>In above image you can see Google Adsense being displayed in articles for my blog.</p><p>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.</p><p><strong>So what's the solution?</strong></p><p>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).</p><p>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.&nbsp;</p><p>Meet the <a href="https://www.drupal.org/project/block_term">Block Visibilty by Term</a> module</p><blockquote><p><span>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.</span></p></blockquote><p><span>Add this module to your drupal site, and now by configuring your block you should see a following scene</span></p><p><span><img src="http://www.reinisfischer.com/sites/default/files/blockvisibiltysettings…; alt="Block Visibility Settings for Drupal" title="Block Visibility Settings for Drupal" width="931" height="324"></span></p><p><em>Block Visibility Settings for Drupal</em></p><p><span>Now, by checking specific taxonomy terms we can configure for which terms <strong>to display</strong> block, <span style="text-decoration: underline;">unfortunetalty this is not working vice verse.</span></span></p><p>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?</p><p>Anyway, here is the page with Block Terms module on action:</p><p><img src="http://www.reinisfischer.com/sites/default/files/drupalhideblock.jpg&qu…; alt="Drupal Block visibilty" title="Drupal Block visibilty" width="932" height="437"></p><p><em>Hidden Adsense block on Drupal articles</em></p><h2>In Conclusion</h2><p>There are times we need to achieve some specific behaviour &nbsp;- 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.</p><p>And, yes with help of above mentioned module, we can hide Google Adsense block for specific terms (or rather display it on specific terms).</p><p>Drop a comment and/or find more what I have to say on <a href="http://www.reinisfischer.com/drupal-development&quot; target="_blank">Drupal Development</a></p>