I'm creating a site where every page is really rendered on a single page - the homepage. I'd like to make it so page URLs - like /about-us/ - redirect back to the homepage, but keep the same URL (/). For example, if I visit http://example.com/about-us/, I want to see http://example.com/ (scrolled down to the correct section, thanks to some JS), but with the URL still as http://example.com/about-us/.

The template_include action seems like it'd work, but doing this:

function home_template($template) {
  return locate_template(array('index.php'));
add_action('template_include', 'home_template');

causes a full redirect to the homepage for some reason (URL and all). Not sure why. Moving the homepage template to home.php or front_page.php (and update the above code accordingly) doesn't fix the issue.

add_rewrite_rule also seemed promising, but it also seems to simply redirect to the homepage, at least with the following code:

function home_rewrite() {
  add_rewrite_rule('about-us', 'index.php', 'top');
add_action('init', 'home_rewrite');

wp_redirect also doesn't do what I'm looking for.

Any ideas? Thank you!!

  • That actually sounds like a good candidate for a frontend JS framework like Vue.js, it would be far easier, and faster for the end user to look into something like that rather than forcing WordPress to do that.
    – Ben Casey
    Jun 5, 2019 at 1:18
  • Yeah I could maybe do this with Express.JS and use WordPress as a headless CMS, but if this is possible to do with just WordPress I'd really prefer that for this project. Jun 5, 2019 at 5:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.