I am trying to figure out which hooks I can tie into in order to read the incoming URL prior to the query actually being run. A quick look tells me maybe wp_loaded or posts_selection would be good choices but would hate to miss out on something obviously better for my needs.

template_redirect sounded promising but seems to be called after content is selected so I do not think that is going to work.

I thought the rewrite code might help, but the likes of generate_rewrite_rules do not seem to allow for arbitrary code to be executed... it seems to all be geared toward redirecting to existing content.

My goal is to write redirection code that I need to not be tied to an existing piece of content. I have found several plugins that do similar things, but all seem to require that a post or page be added to the system for the redirect to be attached to.

For instance, I want /foo/bar to redirect to /baz, but I don't want to have to create a page foo or a sub-page of foo called bar.

1 Answer 1


@Hi Beau Simensen:

The hook plugsin_loaded is one option, but you can use the plugin I posted for this question to see what plugins are run and in which order and use it to find the hook that works best for you:

Given your goal, you might also find this answer useful:

If that wasn't what you needed please elaborate and I can hopefully offer more.

  • The Creating 301 Redirects for Post, Page... uses template_redirect which seems to come after content has been queried. I verified this with your instrument-hooks plugin. This seems to me to be too late in the process as doing a query would wasted since I know no content will exist there. Love the instrument-hooks plugin, btw! Sep 8, 2010 at 18:49
  • @Beau Simensen: That's why I suggested plugsin_loaded at the top of my answer. I was suggesting it with the code in the "Creating 301..." answer. Sep 8, 2010 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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