最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Template includes

programmeradmin1浏览0评论

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?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论