I've found plenty of posts about changing the visibility of a block programatically.

My problem is the opposite. Given a block's ID/delta, how do I find out if it should be displayed at the current path?

I have a field collection that allows you to append a block using the Block Reference module (I preprocess the field collection and use my own template, so the logic has been taken away from the Block Reference module). It works, but I only want it to kick in if the "Show block on specific pages" rule says that block should be displayed.

1 Answer 1


To test the block style visibility rules, you can use drupal_match_path

For example, in core: block_block_list_alter

Checks the page, user role, and user-specific visibility settings. Removes the block if the visibility conditions are not met.

  • Thank you. This is the approach I ended up using. I was hoping that Drupal would offer that as part of the block loading process as it feels somewhat like reinventing the wheel, but so be it.
    – Geat
    Commented Feb 2, 2017 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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