Title: PHP if elseif problem
Last modified: August 19, 2016

---

# PHP if elseif problem

 *  Resolved [meamusta](https://wordpress.org/support/users/meamusta/)
 * (@meamusta)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/)
 * I’m modifying a theme to better suite my needs, but run into a mysterious problem.
   In my sidebar.php I have:
 *     ```
       <?php
         if (is_front_page() and dynamic_sidebar('Home Page')) { }
         elseif (is_page() and dynamic_sidebar('Page Default')) { }
         elseif (is_single() and dynamic_sidebar('Single Post')) { }
         else { }
       ?>
       ```
   
 * But for some reason this does not work. WordPress does not even compile (if that
   is the correct term) my sidebar.php when it looks like that. But when I remove
   one of the lines beginning with “elseif” statements, sidebar.php compiles and
   theme works nicely (only missing the removed functionality).
 * Could someone please tell me what is wrong with my code.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Spencer Hill](https://wordpress.org/support/users/ws5f3dj7/)
 * (@ws5f3dj7)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1157916)
 * This may not address your issue – but try replacing “and” with “||”
 *  Thread Starter [meamusta](https://wordpress.org/support/users/meamusta/)
 * (@meamusta)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1157926)
 * It looks like it is the line
 *     ```
       elseif (is_single() and dynamic_sidebar('Single Post')) { }
       ```
   
 * which is causing problems. Perhaps the “is_single()” function, because I tried
   to change the “Single Post” sidebar to another, but no luck. I’ll continue debugging
   tomorrow.
 *  Thread Starter [meamusta](https://wordpress.org/support/users/meamusta/)
 * (@meamusta)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158053)
 * Replacing “and” with “||” would break the logic in the code. I want the sidebar‘
   Home Page’ to be loaded to my front page, sidebar ‘Page Default’ to any other
   page and ‘Single Post’ when user browses to any single post.
 * If I replace “and”s with “||” sidebar ‘Home Page’ would be shown in any situation.
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158054)
 *  Thread Starter [meamusta](https://wordpress.org/support/users/meamusta/)
 * (@meamusta)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158071)
 * Could be I misused the is_single() function here. I should use the is_post() 
   instead. is_single need an argument also to check if a particular post is displayed,
   but I just need to find out if any post is displayed.
 *  [MAzCastro](https://wordpress.org/support/users/fmacastro/)
 * (@fmacastro)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158073)
 * Perhaps what ws5f3dj7 meant was ´&&´ and not ´||´
 * MAC 🙂
 *  [novinar](https://wordpress.org/support/users/novinar/)
 * (@novinar)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158085)
 * [http://www.leodata.de](http://www.leodata.de)
 *  [novinar](https://wordpress.org/support/users/novinar/)
 * (@novinar)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158198)
 * [http://www.leodata.de](http://www.leodata.de)
 * The best of webdesign.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘PHP if elseif problem’ is closed to new replies.

 * 8 replies
 * 5 participants
 * Last reply from: [novinar](https://wordpress.org/support/users/novinar/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/php-if-elseif-problem/#post-1158198)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
