I have several custom page templates in my theme. But I want to hide a few with a plugin, and only show the custom home page template on the page that has been set as the front page "is_front_page" or "is_home". This is what I am using in my plugin to stop some of the page templates from showing up.
This is for a large multisite where there are two tiers of sites, one gets the full set of features, and the other a stunted set. I have everything working as I need except for this.
add_filter( 'theme_page_templates', 'je_remove_page_template' );
function je_remove_page_template( $pages_templates ) {
unset( $pages_templates['page-topimage.php'] );
unset( $pages_templates['page-home.php'] );
return $pages_templates;
}
The code above works totally fine, but I need a conditional in there to show the page-home.php when the page has been set to the home page. I have tried this code, but it doesn't work.
if ( is_front_page() ) :
add_filter( 'theme_page_templates', 'je_remove_page_template' );
function je_remove_page_template( $pages_templates ) {
unset( $pages_templates['page-topimage.php'] );
return $pages_templates;
}
else :
function je_remove_page_template( $pages_templates ) {
unset( $pages_templates['page-topimage.php'] );
unset( $pages_templates['page-home.php'] );
return $pages_templates;
}
endif;
Any ideas on how I can get this to work?