I am writing a plug-in that creates new front/home page from scratch. Below code works nice and it outputs the text before the themes outputs anything. So the question is how can I remove the theme creating any html code?

Basically I want the plug-i to start with blank home page regardless of any theme that is currently active.

  add_action('wp_head', 'new_front_page');
    function new_front_page(){
     if (is_front_page()){
       echo 'is_front_page():'.is_front_page();

I am testing this on wp 3.6 and twenty thirteen.

Of course anyone is welcomed to suggest better what how to do that.

1 Answer 1


If you want to replace the theme home page, you cannot use wp_head hook: it is called from a theme file (usually header.php) so you can't replace something that is already included.

I suggest you to create a php file that contain your custom home page, and put it in a plugin folder. This file, e.g. 'my_custom_home_page.php', has to create the entire html for the page.

You can't use function like get_header or get_footer because this function include theme template files...

Following code is just a starting point. Using it, the plugin file 'my_custom_home_page.php' is included when the front page is required.

After return you have to put the full path of the custom home page file. The code I used works if the code is in the main plugin file and 'my_custom_home_page.php' is in the same folder. If you have a different folder structure or the code is elsewhere change the path according to it.

add_filter( 'template_include', 'my_replace_home_page' );

function my_replace_home_page( $template ) {
  if ( is_front_page() ) {
    return plugin_dir_path( __FILE__ ) . 'my_custom_home_page.php';
  return $template;
  • Works smoothly. Thank you. So now I have to take care of <!DOCTYPE html> , <head> etc by myself?
    – Radek
    Commented Aug 17, 2013 at 10:25
  • 1
    Sure. All the page depends on you: if you want your plugin be theme agnostic you can't rely on existing theme. A side note: consider that theme always have template tag like wp_head() and wp_footer() and a lot of plugins assume these template tags are called in every site page. So consider adding these template tags in your custom page for other plugins compatibility.
    – gmazzap
    Commented Aug 17, 2013 at 10:39
  • If I want to use jQuery, how can I do that?
    – Radek
    Commented Aug 17, 2013 at 11:27

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.