Wordpress Contact form 7重定向延迟

Wordpress Contact form 7 redirect delay

当新用户注册时,我正在使用联系表 7 重定向。 当用户注册时会显示一条消息,但重定向是即时发生的,所以没有时间阅读消息。

有没有办法用 Javascipt 延迟重定向?

停用您用于 form submission redirect 插件

放在functions.php

add_action( 'wp_footer', 'prefix_my_footer_scripts' );
function prefix_my_footer_scripts(){
  ?>
    <script>
    document.addEventListener( 'wpcf7mailsent', setTimeout(function( event ) {
        location = 'http://example.com/';
    }, false ), 1000); // Replace location and 1000(ms) as your wish
    </script>

  <?php
}

see more

您可以使用 Contact Form 7 的自定义 DOM 事件来实现此目的。您需要将代码中的http://example.com/替换为您要重定向到的URL。

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'http://example.com/';
}, false );
</script>

已接受的答案对我不起作用。它在页面加载时触发。所以我是这样写的:

add_action( 'wp_footer', 'load_footer_scripts' );
function load_footer_scripts(){
    ?>
    <script>
        document.addEventListener( 'wpcf7mailsent', function( event ) {

            setTimeout(function( event ) {
                location = 'http://example.com/';
            }, 4500 );

        }, false );
    </script>
<?php
}