admin管理员组文章数量:1278852
I'm using code that redirects to a “Thank You” page after sending a message from Contact Form 7. This code is located in the child theme's functions.php file.
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = "//site/thank-you/";
}, false );
</script>
<?php
}
This code works, except that there is a Polylang plugin on the site. That's why I have the “Thank you” page in several languages.
- site/thank-you/
- site/ar/thank-you/
- site/zh/thank-you/
If I switch to Arabic or Chinese, it still redirects to the //site/thank-you/ page by default.
How can I fix this and make the redirect to the “Thank You” page depending on the selected language?
I'm using code that redirects to a “Thank You” page after sending a message from Contact Form 7. This code is located in the child theme's functions.php file.
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = "//site/thank-you/";
}, false );
</script>
<?php
}
This code works, except that there is a Polylang plugin on the site. That's why I have the “Thank you” page in several languages.
- site/thank-you/
- site/ar/thank-you/
- site/zh/thank-you/
If I switch to Arabic or Chinese, it still redirects to the //site/thank-you/ page by default.
How can I fix this and make the redirect to the “Thank You” page depending on the selected language?
Share Improve this question asked Feb 24 at 14:02 DmitryDmitry 1651 gold badge12 silver badges41 bronze badges 1 |1 Answer
Reset to default 2I don't know much about "Polylang" plugin but upon searching "pll_get_post" might do it.
replace your code with this code and "1" with your thank you page post id.
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
if ( function_exists( 'pll_get_post' ) ) {
// Get the translated Thank You page URL
$page_id = 1; // Replace with the actual Thank You page ID in default language
$new_thank_you_url = get_permalink( pll_get_post( $page_id ) );
}
?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = "<?php echo esc_url( $new_thank_you_url ); ?>";
}, false );
</script>
<?php
}
Here is the link if you want to study about the function
https://polylang.wordpress/documentation/documentation-for-developers/functions-reference/
本文标签: phpRedirects to the “Thank you” page depending on the selected language in WordPressStack Overflow
版权声明:本文标题:php - Redirects to the “Thank you” page depending on the selected language in WordPress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741265496a2368385.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
lang
attribute of thehtml
element. – C3roe Commented Feb 24 at 14:29