Automatically Close Popup After 10 Seconds

The following code sample is designed to close a popup (ID: #pum-123 ) after 10 seconds. 

Copy, paste, and edit the following code in your child theme's functions.php file, or use the My Custom Functions plugin to install the code for you.

Replace the popup ID number in the code example with the value assigned to your popup. You can find the ID is by going to  Popup Maker > All Popups > CSS Classes. The integer value is appended to the class name 'popmake-'

 *  Note 1: Replace the placeholder popup ID used below ('#pum-123') with
 *  the value '#pum-{integer}'.  From the WP Admin, refer to 'Popup Maker'
 *  -> 'All Popups' -> 'CSS Classes (column)' -> to find the integer value
 *  assigned to the popup targeted to close with this code snippet.
 *  Note 2: In the code example below, the units of time are milliseconds (ms).
 *  1 second = 1000 ms; 10 seconds = 10000 ms.
 *  Add the following code to your theme (or child-theme)
 *  'functions.php' file starting with 'add_action()'.
 * -------------------------------------------------------------------------- */
add_action( 'wp_footer', 'my_custom_popup_scripts', 500 );
 * Add a script to automatically close a popup after X seconds.
 * @since 1.0.0
 * @return void
function my_custom_popup_scripts() { ?>
    <script type="text/javascript">
        (function ($, document, undefined) {

            $('#pum-123') // Change 123 to your popup ID number.
                .on('pumAfterOpen', function () {
                    var $popup = $(this);
                    setTimeout(function () {
                    }, 10000); // 10 Seconds

        }(jQuery, document))

View the source on GitHub.

If you need help adding PHP code to your site, check out our Getting Started with Custom PHP guide.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.