I would like to add a around a menu block I am displaying on a section of my site to style it differently on a certain page only.

How do I do this? Can I target a certain page with a conditional somehow?


If your theme utilizes body classes and you don't need to modify the HTML structure you can simply do:

body.page-node-1 #block-block-1 {
  /* styles goes here */

Replace "1" above with the ID's for the node and the block.



First, get fully familiar with Template Suggestions (here is a good reference) then

A. copy block.tpl.php to your theme if it's not there already, and then,

B. copy it to block-MENU-DELTA.tpl.php where MENU-DELTA is the correct incantation of menu and name/delta for your block, then,

C. Inside this new template, put in some logic that does whatever differently based upon what page you are looking at. Easiest is to do wrap your html in an if keyed off $_GET['q'], eg, something like:

<?php if ($_GET['q']=='page/we/are/looking/for'): ?>
   // custom html here
<?php else: ?>
   // regular html here
<?php endif; ?>
  • Thanks for the response. I was trying this from that page you suggested and was running into issues. However, this solution will work also. Apr 17 '13 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.