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


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

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

| improve this answer | |
  • It makes sense! I can't thank you enough! Regards. – Serdar Koçak Jan 25 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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