One page themes have become increasingly popular this year, and I'm just working on my first. Although the site's navigation doesn't offer any direct links to the individual pages that make up my one-page presentation, I know it's always possible that someone will try to access them directly, or that they may appear in search engine results. So I'm interested in your ideas on best practices for forcing users back to where I want them.

Example, my one-page site is comprised of About, Gallery and Contact. These are built as pages so that the user can easily update them, but they are pulled into one single page for display, and are accessed via anchor IDs. So mysite.com/#about etc. But if someone types mysite.com/about, I want to force them back to the main page and the anchor point rather than having a single page view of that content. (maybe I'm wrong about this, and if you think so, tell me why)

I suppose the easy answer is just to do a rewrite rule to precede any reference to a direct page with the hashtag. But imagine that down the road I'd like to add a blog section that is not contained on the page but that opens a new one?

So far my Google searches haven't turned up much discussion on the subject. Maybe it's my search terms that are amiss - so I'd love to hear your ideas, and if you've read any good articles that discuss this, please pass them along!

  • Please clarify how this question is specific to WordPress. – Chip Bennett Nov 6 '13 at 14:25

Two (give or take) points to consider here.

One - we don't want anyone to see direct links in first place. Scrubbing them from admin side is quite a pain, but a post_link filter in get_permalink() (and maybe couple more filters in others) should allow to (mostly) override those.

Two - we don't want users or search engine either to get "normal" page. In a nutshell whenever normal page is visited we want to:

  1. Check in template_redirect hook if it's the one not to be visited.
  2. 301 (really, really mean it) redirect it to correct place (using wp_safe_redirect() for example) if so.
| improve this answer | |
  • Thanks Rarst. I've got point 1 covered, it's point 2 that I'm studying more closely. For this project, I think I will do a simple rewrite because the same simple rule can apply for all pages, and still leave room if the user wants to add a section. Though I'm still interested in mixing techniques that would redirect on some pages, and not others, without having to write individual redirects…maybe asking too much :) surprised I can't find more discussion on the topic seeing how popular these one pagers are…thnx. – Jenny Beaumont Nov 6 '13 at 14:37
  • What about using conditional; if(!is_home()) with the template_redirect hook? – TomC Nov 6 '13 at 15:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.