admin管理员组文章数量:1122846
I'm trying to create a subpost location - like /embed or /feed - for photo galleries.
// this defines the location logic
if (!function_exists('is_gallery')) {
function is_gallery() {
$uri = $_SERVER['REQUEST_URI'];
$parts = array_values(array_filter(explode('/',$uri)));
if(end($parts) == 'gallery') {
return true;
}
}
}
// this loads the template
add_action('template_include','gallery_page');
function gallery_page($template) {
if(is_gallery()) {
status_header(201);
global $wp_query;
$wp_query->is_404 = false;
$wp_query->is_singular = true;
$new_template = locate_template(array('gallery.php'));
if ('' != $new_template) {return $new_template;}
}
return $template;
}
So whatever the template outputs is available at example/post-name/gallery
It works fine like this, but notice the 201 (could be 203 as well) http status header. If I use the appropriate 200, it no longer works, as wordpress does some random 302 redirect, usually to the parent url but not always.
What I'm trying to do is prevent that redirection. It's possibly triggered by wp_safe_redirect()
in wp-includes/pluggable.php but from there I couldn't figure out a filter to stop it.
Disabling canonical redirects – with add_filter('redirect_canonical', '__return_false');
or it's 'remove...' variations – doesn't help either.
And neither does setting true some random values of wp_query, but maybe there's something I'm missing.
So what I want is to stop that redirection or somehow have this work with a proper status of 200.
本文标签: wp queryHow to prevent random 302 canonicalish redirect on custom template
版权声明:本文标题:wp query - How to prevent random 302 canonical-ish redirect on custom template 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309528a1934052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论