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 by going to Popup Maker > All Popups > CSS Classes. The integer value is appended to the class name popmake-
.
<?php
/**
* Note 1: Replace the placeholder popup ID used below ('#pum-123') with
* the value '#pum-{integer}'. From the WP Admin, go to Popup Maker
* > All Popups. Look at the CSS Classes column. Learn more at
* https://wppopupmaker.com/docs/manage-features-or-options/find-the-popup-id/
*
* Note 2: 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 () {
$popup.popmake('close');
}, 10000); // 10 Seconds
});
}(jQuery, document))
</script><?php
}
View the source on GitHub.
If you need help adding PHP code to your site, check out our Getting Started with Custom PHP guide.