Wordpress 提交后如何将联系人表单7重定向到另一页?

Wordpress 提交后如何将联系人表单7重定向到另一页?,wordpress,contact-form-7,Wordpress,Contact Form 7,我试图在点击联系人表单提交按钮后重定向到另一个页面,但它不起作用。我正在按照官方指南进行尝试,并将此脚本: <script> document.addEventListener( 'wpcf7mailsent', function( event ) { location = 'http://example.com/'; }, false ); </script> 在“附加首选项”选项卡中,但它不起作用。如何解决此问题?请尝试此代码 add_action( 'wp

我试图在点击联系人表单提交按钮后重定向到另一个页面,但它不起作用。我正在按照官方指南进行尝试,并将此脚本:

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'http://example.com/';
}, false );
</script>
在“附加首选项”选项卡中,但它不起作用。如何解决此问题?

请尝试此代码

add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '947' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page
location = 'https://www.example.com/thank-you-1/';
} else if ( '1070' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
    location = 'https://www.example.com/thank-you-2/';
} else { // Sends submissions on all unaccounted for forms to the third thank you page
    location = 'https://www.example.com/thank-you-3/';
}
 }, false );
 </script>
 <?php
  }
或者你也可以使用这个插件

更换您的位置http://example.com/'; 使用window.location.href='0http://example.com/';

复制此代码并将其粘贴到子主题的functions.php文件中

/**
 * Redirect user to hard coded link when form data is submitted.
 */
function contact_form_login_redirect() {
    ?>
    <script>
        document.addEventListener( 'wpcf7mailsent', function ( event ) {
            location = 'http://example.com/';
        }, false );
    </script>

    <?php
}

add_action( 'wp_footer', 'contact_form_login_redirect' );

我试过了,它对我来说很好

仍然不起作用,关于这个插件,我想我需要通过代码来实现它。但是谢谢你!