I use front-page.php on my template to display home page. But I want to disable if the user uses another page for the home page from settings. Is there a solution? When user select a page from settings for home page, it not showed and front-page.php is loaded. I want to it disabled dynamically. Sorry for bad english.
I use front-page.php on my template to display home page. But I want to disable if the user uses another page for the home page from settings. Is there a solution? When user select a page from settings for home page, it not showed and front-page.php is loaded. I want to it disabled dynamically. Sorry for bad english.
Share Improve this question asked Apr 22, 2019 at 13:17 user3364610user3364610 112 bronze badges2 Answers
Reset to default 2Maybe template_include
filter would get the job done for you. Something along these lines,
function prefix_another_front_page_template( $template ) {
if ( is_front_page() ) {
$another_front_page_template = 'something.php'; // adjust as needed
$new_template = locate_template( array( $another_front_page_template ) );
if ( !empty( $new_template ) ) {
return $new_template;
}
}
return $template;
}
add_filter( 'template_include', 'prefix_another_front_page_template', 99 );
Just don't use front-page.php then. As you can see in the template hierarchy if the user doesn't select a front page then home.php will be used. So you can use this for the front page if a user doesn't have a page set, and then if you don't include front-page.php in your template the theme will fall back to the default page template if they do select a page.