WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering if there is an easy solution to add some php "if" code when my website tries to show the widgets and if it has $_SESSION I set on homepage (based on the source of which they came) not to show one of them?

share|improve this question

The easiest way to do this is via dynamic_sidebar()

if ($a == $b)  // Your $_SESSION stuff
  dynamic_sidebar( 'Right Sidebar' );

Any widgets contained in the "Right Sidebar" will now be loaded based on your condition. You should use this with register_sidebar()


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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