0

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.com/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.com/fr, then you'll be redirected automatically to example.com/fr/thank-you page.

If we use blog-id or subdirectory name in the above snippet, it might help?

WP Multisite method: subdirectory

Regards.

2
  • Yes, you can use the blog_id, and add a conditional or switch.
    – WebElaine
    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? Jan 24, 2020 at 15:02

1 Answer 1

1

If 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

1
  • It makes sense! I can't thank you enough! Regards. Jan 25, 2020 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.