Is there a way to hide a template file in admin?
For example I have a template that should only be available if a specific plugin is installed, and I already know how to check if plugin is active. But how do I hide the template?
For example I want to hide “Blogger Redirection”-template bellow:

I have found several links, but all of the solutions seems deprecated.
EDIT: If anyone is interested in how I check if pluin is active I do it with the following function:
function isPluginActive($plugin){
if ( in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
{
return true;
}
return false;
}
Update – a word of caution as pointed out by andrew in the comments below:
I’m not sure if there is a PHP way of doing this – you’ll have to look in the
WP_Themeclass, but from my first look it might not be possible because in order to get all templates, the class utilizes an internal function calledscandir()which scans the current theme directory and gets all.phpfiles from there. It then looks for the correspondingTemplate Name:identifier and if it’s present it gets added to the templates list.So instead I suggest, that you add a little JS that will remove this option from the page template select. Here’s a code snippet:
This will remove the template
sidebar-page.phpfrom the dropdown. The conditionals are so that the script is only added on add and edit screens of pages.Adjust to your case and enjoy 🙂