Title: Open Popup with conditional PHP code
Last modified: June 18, 2017

---

# Open Popup with conditional PHP code

 *  Resolved [capariciof](https://wordpress.org/support/users/capariciof/)
 * (@capariciof)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/open-popup-with-conditional-php-code/)
 * Hello, you know how I can make the popup open automatically using a command in
   php or html?
 * I have a condition function (if… else) in php and I require the popup to open
   with one certain condition.

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

 *  Plugin Author [Damian](https://wordpress.org/support/users/timersys/)
 * (@timersys)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/open-popup-with-conditional-php-code/#post-9241072)
 * Hi [@capariciof](https://wordpress.org/support/users/capariciof/),
    you usually
   don’t want to use php to open the popup because of page cache (if you are using
   any) But if you still need to do it, all you can do is wrap javascript code within
   your PHP conditional EG:
 *     ```
       <?php if( condition ) : ?>
           <script>SPU.open('123');</script>
       <?php endif;?>
       ```
   
 * I do recommend using the shortcode generator or using pure html such as :`<a 
   href="#" class="spu-open-123">Click here</a>`
 * You can use the spu-open-XXX class with any html element. Simple replace XXX 
   with your popup ID.
 * If you like the plugin / support please [leave a short review](https://wordpress.org/support/view/plugin-reviews/popups?filter=5).
   It’s a tremendous help for us!
 * Thanks
 *  Thread Starter [capariciof](https://wordpress.org/support/users/capariciof/)
 * (@capariciof)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/open-popup-with-conditional-php-code/#post-9242907)
 * Does this code need to be located in any special position?
 *  Plugin Author [Damian](https://wordpress.org/support/users/timersys/)
 * (@timersys)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/open-popup-with-conditional-php-code/#post-9246293)
 * not really, but at a side note, this won’t work on ajax mode because the code
   will be printed before the popup exists.

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

The topic ‘Open Popup with conditional PHP code’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/popups_efeef0.svg)
 * [Popups - WordPress Popup](https://wordpress.org/plugins/popups/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/popups/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/popups/)
 * [Active Topics](https://wordpress.org/support/plugin/popups/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/popups/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/popups/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Damian](https://wordpress.org/support/users/timersys/)
 * Last activity: [8 years, 11 months ago](https://wordpress.org/support/topic/open-popup-with-conditional-php-code/#post-9246293)
 * Status: resolved