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;
}