Redirect after 5 seconds of the wordpress click

0

Under Wordpress CMS, what I'm looking for is that after 5 seconds of clicking on a specific button the page is redirected to another url obtained by a php variable.

    <script type="text/javascript">
function sample() {
   setTimeout(function() {
       window.open('<?php echo esc_attr(wpcoupon_coupon()->get_go_out_url()); ?>', '_self');
   }, 5000); 
}
</script>  

And on the button:

<button class="ui right labeled icon button btn btn_secondary" onClick="sample();">
<i class="copy icon"></i>
<span><?php esc_html_e('Copy', 'wp-coupon'); ?></span>

The issue is that in a php file outside of wordpress and varying from the script <?php echo esc_attr(wpcoupon_coupon()->get_go_out_url()); ?> by link works correctly, but by integrating the codes in single.php the url to which it redirects is example.com/nombre-de-la-entrada/url , adding that last url when the redirect is executed. I have tried to show by php <?php echo esc_attr(wpcoupon_coupon()->get_go_out_url()); ?> and the url that our is correct.

Thank you very much in advance

    
asked by Pauet 22.06.2018 в 10:20
source

2 answers

0

Hello this you can do it in the following way:

<?php
header('Location: http://www.example.com/');
?>

Another way is to put a meta tag on the destination php page

//redirecciona en 10 segundos
<meta http-equiv=""refresh content="10,url=http://example.com"/>

Another way is that you use javascripts, but if you use a script blocker it will be canceled

    //primero el php
    <?php
    header ("refresh:10; url=https://example.com/index.php");
    ?>

        //Ahora agregas el javascript
        <script>
        (function() {
        var timeleft = 10,
        cinterval;

        var timeDec = function (){
        timeLeft--;
        document.getElementById('countdown').innerHTML = timeleft;
        if(timeleft === 0){
        clearInterval(cinterval);
           }
        };
        cinterval = setInterval(timeDec, 1000);
        })();

        </script>

// te agregare el enlace porque algunas veces me preguntan 
//el procedimiento, creas el estilo del boton con CSS

<?php 
echo "<a href="ir.php" class=\"boton\">Boton</a>";
//ir.php tiene toda la funcion de temporizacion
?>

You let me know how it worked for you

    
answered by 22.06.2018 в 16:37
0

php has a feature called sleep is available since version 4

an example of how to use it

<?php

// current time
echo date('h:i:s') . "\n";

// sleep for 10 seconds
sleep(10);

// wake up !
echo date('h:i:s') . "\n";

?>

Here you have the link of the documentation

    
answered by 27.06.2018 в 10:38