【发布时间】:2017-11-19 11:01:28
【问题描述】:
我有一个 wordpress 网站,我想将特定链接重定向到我的自定义链接。我不想使用任何插件,并希望通过在 functions.php 文件中编写代码来实现这一点。我试过的代码写在下面
function custom_redirect() {
if(is_page(7)) {
wp_redirect('http://example.com/my-account/orders/', 301);
exit();
}
}
add_action ('template_redirect', 'custom_redirect');
现在,我想要重定向用户的页面 ((is_page(7))) 的 url 是 http://www.example.com/my-account/,我想将他们重定向到 http://www.example.com/my-account/orders。我也尝试了site_url('/my-account/') 功能,但无法实现。
【问题讨论】:
-
使用 is_page(7) 有什么意义,这和我的帐户是同一个页面吗?
-
是的。
is_page(7)是'example.com/my-account',我想重定向到'example.com/my-account/orders'。