【发布时间】:2014-10-17 10:37:39
【问题描述】:
我正在使用 Wp Store Locator 插件。我已根据需要对其进行了修改。但我陷入了重定向。
这个插件基本上可以使用短代码。所以在列出我的 URL 时是这样的:localhost/wordpress/?page_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_id=391 可能是什么问题?
任何人都可以建议我在 URL 中检测到 wpsl_id 时如何定向到 URL?我想将它们重定向到插件的模板文件夹,我已经为此添加了一个文件。
已编辑:
我在短代码上方的插件文件中添加了上述代码。希望我与这个问题无关:)
【问题讨论】:
-
您的
wp_redirect()函数正在重定向到页面模板,而不是有效的站点 URL... -
你必须使用
template_include过滤钩子而不是template_redirect。 codex.wordpress.org/Plugin_API/Filter_Reference/… -
@rnevius 对不起,我没有得到你。我错过了什么?或者我在哪里犯错了?
-
@jogesh_pi 您的建议不起作用.. 实际上它没有显示任何内容。只有空白页。
标签: wordpress redirect plugins