Panel blocks display based on url selection rule

Last updated on
30 April 2025

Problem:

I needed to create alternative panel page layout based on my url. Some of the content would not be used for the mobile site and needed to disappear. I had created a mobile site with the m. prefix and then change my layout based on whether the user was visiting from a mobile device. (the m. site )

(To configure you mobile theme switching and configuration check out http://cruncht.com/419/mobile-drupal-site-setup/ )

Solution:

  1. Navigate to the content of the panel page you would like to change.
  2. On the panel you want to remove select the gear in the right hand corner -> select visibility rules -> add new rule
  3. Select php code.
  4. then add in the PHP code text area
  5. return $_SERVER['HTTP_HOST'] == ' MAIN SITE URL HERE (foo.com)';
    /**
    *UPDATE
    */
    You can also base this rule on the theme. Most likely if you are using this approach you will be using 2 themes, in which cause the visibility rule goes against the theme and *not the uri so youu would have
    return $theme == 'THEME-NAME';

  6. Save it and you're done.

Now that panel has to have a url of foo.com for it to be seen. You can change the order if you have a panel that you only want to be seen on the m.foo by just added that mobile site url.

Help improve this page

Page status: Not set

You can: