Wordpress 如何基于URL重定向
我正在使用Wp商店定位器插件。我已经根据需要对其进行了修改。但是我被重定向卡住了 基本上,这个插件使用的是短代码。因此,在列出我的URL时是这样的:Wordpress 如何基于URL重定向,wordpress,redirect,plugins,Wordpress,Redirect,Plugins,我正在使用Wp商店定位器插件。我已经根据需要对其进行了修改。但是我被重定向卡住了 基本上,这个插件使用的是短代码。因此,在列出我的URL时是这样的:localhost/wordpress/?page\u id=391 现在有一个链接将我重定向到http://localhost/wordpress/?wpsl_id=3 下面是代码: add_action("template_redirect", 'my_theme_redirect'); function my_theme_re
localhost/wordpress/?page\u id=391
现在有一个链接将我重定向到http://localhost/wordpress/?wpsl_id=3
下面是代码:
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
$dpath = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ;
$templatefilename = 'single-store.php';
if (strpos($dpath,'wpsl_id') !== false){
$return_template = get_template_directory() .'/' .$templatefilename ;
//$nurl = get_permalink($return_template);
//echo $return_template; exit;
wp_redirect($return_template);
exit;
}
}
此代码没有将我重定向到任何位置。它停留在同一页面上localhost/wordpress/?page\u id=391可能有什么问题
任何人都可以建议我在URL中检测到wpsl\u id
时如何指向URL?我想把它们重定向到插件的模板文件夹,在那里我添加了一个文件
已编辑:
我在插件文件中添加了上面的代码,就在短代码的上面。希望我与此问题无关:)模板名称看起来不错。您只需要在调用模板之前注册它 添加此筛选器,以便在执行操作之前执行:
添加过滤器('template_include'、'single store') 您的
wp\u redirect()
函数正在重定向到页面模板,而不是有效的站点URL…您必须使用template\u include
过滤器挂钩,而不是template\u redirect
@很抱歉我没抓住你,我错过了什么?或者我哪里出错了?@jogesh_pi你的建议不起作用。。事实上,它没有显示任何东西。只有空白页。你对Wordpress很陌生。请给出有用的答案或在回答之前搜索,否则你会有否决票。Dude第二个参数必须是函数,而不是页面名称。谢谢你的时间。我找到了解决方案,一旦您使用template_include钩子添加了模板,那么您就可以正确地调用您的模板,这是人们试图告诉您的。