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

hooks - Make multiple URLs behave as home page

programmeradmin1浏览0评论

I want /url1, /url2, /url3, to all behave as though the homepage / was accessed, and to have the homepage rendered without redirecting away from /urlx. In fact, if every URL someone tried to access was rendered as the home page, that would be great.

No need for SEO advice, or learning about redirects to the canonical page. This is a special use-case and I need this specific outcome.

I have tried resetting the query by hooking in to pre_get_posts() and calling wp_reset_query(), but that doesn't change any functionality on any page.

add_action( 'pre_get_posts', function($query) {
    wp_reset_query();
} );

Even if I could get every page on my site to render as the home page without redirecting, I could make the rest of the changes I need. Can anyone help?

I want /url1, /url2, /url3, to all behave as though the homepage / was accessed, and to have the homepage rendered without redirecting away from /urlx. In fact, if every URL someone tried to access was rendered as the home page, that would be great.

No need for SEO advice, or learning about redirects to the canonical page. This is a special use-case and I need this specific outcome.

I have tried resetting the query by hooking in to pre_get_posts() and calling wp_reset_query(), but that doesn't change any functionality on any page.

add_action( 'pre_get_posts', function($query) {
    wp_reset_query();
} );

Even if I could get every page on my site to render as the home page without redirecting, I could make the rest of the changes I need. Can anyone help?

Share Improve this question edited Jun 18, 2020 at 17:02 Mort 1305 9835 silver badges18 bronze badges asked Jun 17, 2020 at 16:01 Neal BozemanNeal Bozeman 1012 bronze badges 1
  • If you only have a homepage and no other content, you could create a custom theme where the only PHP file is "index.php." This would force WP to render the same content no matter what URL someone landed on. – WebElaine Commented Jun 17, 2020 at 16:32
Add a comment  | 

1 Answer 1

Reset to default 0

Just intercept the hook to determine which template to use. To make all pages act as the homepage:

add_filter( 'template_include', function($template) {
    return get_template_directory() . '/index.php';
});
发布评论

评论列表(0)

  1. 暂无评论