The below code redirects visitors to any page that you want.
// Redirect to thank you post after comment
add_action('comment_post_redirect', 'redirect_to_thank_page');
function redirect_to_thank_page() {
return '';
}
However, I use WP Multisite feature and the same active theme is used by all subsites in the network. So can I redirect visitors according to the subsite which they visit?
i.e. if you leave a comment on example/fr, then you'll be redirected automatically to example/fr/thank-you page.
If we use blog-id or subdirectory name in the above snippet, it might help?
WP Multisite method: subdirectory
Regards.
The below code redirects visitors to any page that you want.
// Redirect to thank you post after comment
add_action('comment_post_redirect', 'redirect_to_thank_page');
function redirect_to_thank_page() {
return 'https://example/thank-you';
}
However, I use WP Multisite feature and the same active theme is used by all subsites in the network. So can I redirect visitors according to the subsite which they visit?
i.e. if you leave a comment on example/fr, then you'll be redirected automatically to example/fr/thank-you page.
If we use blog-id or subdirectory name in the above snippet, it might help?
WP Multisite method: subdirectory
Regards.
Share Improve this question asked Jan 24, 2020 at 12:29 Serdar KoçakSerdar Koçak 522 silver badges7 bronze badges 2- Yes, you can use the blog_id, and add a conditional or switch. – WebElaine Commented Jan 24, 2020 at 14:27
- @WebElaine Thank you for the answer, WebElaine. I've been learning Javascript for 2 months but still, I don't know PHP. Can you please help me to create that function? – Serdar Koçak Commented Jan 24, 2020 at 15:02
1 Answer
Reset to default 1If you have a thank-you-page with same slug in all sites you can do:
add_action('comment_post_redirect', 'redirect_to_thank_page');
function redirect_to_thank_page() {
return get_bloginfo('url').'/thank-you-page';
}
get_bloginfo('url')
detects the subsite you're currently in