最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multisite - 301 Redirection After Comment

programmeradmin5浏览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 '';
}

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
Add a comment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论