apply_filters( 'theme_page_templates', array $page_templates, WP_Theme $this, WP_Post|null $post )

Filters list of page templates for a theme.


$page_templates array
Array of page templates. Keys are filenames, values are translated names.
$this WP_Theme
The theme object.
$post WP_Post|null
The post being edited, provided for context, or null.

Top ↑


File: wp-includes/class-wp-theme.php. View all references

Top ↑


Version Description
4.4.0 Converted to allow complete control over the $page_templates array.
3.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Julie Kuehl

    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.

    /* Remove parent theme page templates */
    function child_remove_page_templates( $page_templates ) {
      unset( $page_templates['template-cover.php'] );
      unset( $page_templates['template-full-width-cover.php'] );
      unset( $page_templates['template-full-width-only-content.php'] );
      unset( $page_templates['template-full-width.php'] );
      unset( $page_templates['template-only-content.php'] );
      return $page_templates;
    add_filter( 'theme_page_templates', 'child_remove_page_templates' );
    add_filter( 'theme_post_templates', 'child_remove_page_templates' );
  2. Skip to note 2 content
    Contributed by SpartakusMd

    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:

     * 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 );

You must log in before being able to contribute a note or feedback.