admin管理员组文章数量:1332713
I want to use custom template redirects for urls such as and
I'm using add_rewrite_rule
function for this
add_action('init', function() {
add_rewrite_rule( "^foo/([^/]*)/?", 'index.php?foo=1&bar=$matches[1]', 'top' );
})
Then I set the variables
add_filter( 'query_vars', function( $vars ){
$vars[] = 'foo';
$vars[] = 'bar';
return $vars;
}
add_filter('template_include', function($original_template) {
if(get_query_var('foo')) {
return '/my-template.php'
} else {
return $original_template;
}
}
It works fine for links like and in my template I can use bar variable.
get_query_var('bar');
But / returns the 404 error.
Can I make this link with template redirect too?
本文标签: Template includes
版权声明:本文标题:Template includes 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742340514a2456507.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论