How to automatically close popup and redirect user?

There's a popup on the page. How to make it close automatically after x time and then automatically redirects the user to a given site?

To see it, use support access to access the site, then open "http://++++beacons.co/login", click on "Redemption center" accordion and click on "Change" button there. you'll see the popup - this should be automatically closed and then redirectd automatically to a "parent"/"referrer" page.

  • Predrag Dubajic

    Hi Kai,

    Hope you're well :slight_smile:

    Popup plugin doesn't have such functionality and it requires some custom coding to have such behavior.

    What we can do is use some jQuery and apply it on the same button used to open the popup, so it redirects to desired page after certain time.
    I checked the page in question but I don't see the button there so you will need to adjust the below code a bit in order to work on your setup.

    You can create new .php file in wp-content/mu-plugins/ folder and in that file place this code:

    <?php
    function redirect_after_delay() { ?>
        <script type="text/javascript">
        jQuery(function () {
            jQuery("#btnRedirect").click(function () {
                var seconds = 5;
                setInterval(function () {
                    seconds--;
                    if (seconds == 0) {
                        window.location = "http://domain.com";
                    }
                }, 1000);
            });
        });
        </script>
    <?php }
    add_action( 'wp_footer', 'redirect_after_delay' );

    These are the changes you will need to do:
    #1 in this line of code:
    jQuery("#btnRedirect").click(function () {
    Replace #btnRedirect with the class or ID you are using for your button/link used to open popup.
    #2 In var seconds = 5; change 5 to number of seconds after which the redirect should happen.
    #3 Change the domain in window.location = "http://domain.com"; and set the one where you want to redirect.

    Save the changes and that should be it.

    Hope this helps :slight_smile:

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.