I need to develop a plugin in which a special page needs to be created. This page will have a completely separate design from the rest of the website, and will be located at a specific URL.
I realize short codes are the “proper” way for a plugin to run itself on a page, but how would I go about actually over-riding the entire theme of the page and replace it with my own content? In this case, since it’s a single page, I don’t want to actually create an entire WordPress theme– I just need to be able to essentially start from a blank slate and I can just use my own HTML from there.
Here’s a slimmed-down version of what I usually do. Replace wpse100645 with whatever you want, but be respectful of the fact that you don’t want to interfere with a site’s content.
What’s happening here?
First, we’re adding a query var,
wpse100645
and we’re adding a rewrite rule for that query var. This way, it will work whether the user has permalinks enabled or not, either at domain.com/?wpse100645=1 or at domain.com/wpse100645/.Next, when
parse_query
fires, we check to see if our query var is present. If it is, we run whatever code we want and exit (seedispatch_path
). Therefore, your plugin can render whatever HTML it wants, because no template files have loaded yet. It will be quite fast too, because the main query hasn’t even run yet. This all fires pretty high up in the request chain. Note that if you don’texit
, the homepage will render after your code does.