How would I force WordPress by code to load a template file on my home page? I know how to do it via the backend but I would like to create a plugin and have the option to set the front page from inside the plugin.

Basically, I am looking for the code to force loading a template when the home page is being loaded. So instead of the index.php it would load the plugin template. I can't find anything about this.


Depending on your home page, you either can set up a template file home.php (archive) or front-page.php (static page). In the according file, you can do whatever you want. Run additional queries, load content from whatever source etc.

If this is not what you want, then you can have a look at the template_include filter hook.
If you want/need to do more than just load a specific template file, you might want to have a look at the template_redirect action hook.

  • 2
    don't use template_redirect to modify which template is loaded, that's what the template_include filter is for. – Milo Apr 16 '14 at 18:10
  • i was plannning on using 'if ( ! is_admin() ) ' . Which one should i use? – AlbaClan Apr 16 '14 at 18:23
  • 1
    @Milo I incorporated your comment into the answer. Of course, you are right. When just swapping out the template file, the filter is all you need. – tfrommen Apr 16 '14 at 20:07

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.