I am trying to use a visibility rule in Panels to hide a block based on whether the query string has a parameter (value=5) or not.

Panels provides a String: URL path visibility rule by default, but this seems to only work for the URL path, not the query string.

Is there a way to add a condition to show/hide the block based on one of the parameters in the query string?

3 Answers 3


Using PHP code is not recommended unless absolutely necessary. You never want to store the PHP code in database, you do that in the modules :-)

I would recommend you to write an ctools access plugin for the same; check the logic there and give access to users accordingly.


  1. The code is more maintainable, and can be version controlled.
  2. You could reuse the same visibility rule throughout the site wherever necessary.

Please check my answer here, for an example of a working access plugin.

  • 1
    Yes, as you saw, I had already started working on an access plugin to do this, and I will post it when I get it working. May 25, 2015 at 8:43

Here's the ctools access plugin I made based on AjitS's advice:

It checks for whether the 'd' parameter in the query string has a numeric value or not.

 * @file
 * Plugin to check whether the value matches the query string
 * https://drupal.stackexchange.com/questions/33336/what-are-ctools-plugin-content-type-access-etc-and-how-does-one-create-them/33337#33337

 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
$plugin = array(
  'title' => t("Check for proximity in query string"),
  'description' => t('Returns FALSE if the value is in the query string'),
  'callback' => 'mymodule_checkproxquerystring_ctools_access_check',
  'settings form' => 'mymodule_checkproxquerystring_ctools_access_settings',
  'summary' => 'mymodule_checkproxquerystring_ctools_access_summary',

 * Settings form
function mymodule_checkproxquerystring_ctools_access_settings($form, &$form_state, $conf) {
  return $form;

 * Check for access.
function mymodule_checkproxquerystring_ctools_access_check($conf, $context) {
  if (isset($_GET['d']) && (is_numeric($_GET['d']))) {
    return FALSE;
  else {
    return TRUE;

 * Provide a summary description.
function mymodule_checkproxquerystring_ctools_access_summary($conf, $context) {
  return t('Proximity in query string');

you could use a PHP code selection and use $_GET['q'] to parse the parameters.

  • As mentioned by Ajits, executing php code that is stored in the database is not recommended and dangerous because it's very hard to debug
    – wranvaud
    Jan 19, 2018 at 14:29

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.