If you want to remove templates from both Pages and Posts, you will need to also use the `theme_post_templates` in addition to the `theme_page_templates` filter.
Suppose you have the blog `Food` with the id 2 and the template `page-food.php` which should only be used for this blog. The example below removes the page template from dropdowns of other blogs:
/**
* Filter the theme page templates.
*
* @param array $page_templates Page templates.
* @param WP_Theme $this WP_Theme instance.
* @param WP_Post $post The post being edited, provided for context, or null.
* @return array (Maybe) modified page templates array.
*/
function wpdocs_filter_theme_page_templates( $page_templates, $this, $post ) {
$current_blog_id = get_current_blog_id();
$food_blog_id = 2;
if ( $current_blog_id != $food_blog_id ) {
if ( isset( $page_templates['page-food.php'] ) ) {
unset( $page_templates['page-food.php'] );
}
}
return $page_templates;
}
add_filter( 'theme_page_templates', 'wpdocs_filter_theme_page_templates', 20, 3 );
If you want to remove templates from both Pages and Posts, you will need to also use the `theme_post_templates` in addition to the `theme_page_templates` filter.
Filter page templates by blog id
Suppose you have the blog `Food` with the id 2 and the template `page-food.php` which should only be used for this blog. The example below removes the page template from dropdowns of other blogs:
To filter the “Default template” option in the list of Page Templates, see
default_page_template_title
.