Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21561 closed feature request (wontfix)

is_page_template() doesn't work in admin edit page screen

Reported by: l3rady's profile l3rady Owned by:
Milestone: Priority: normal
Severity: trivial Version: 3.4.1
Component: Template Keywords:
Focuses: Cc:


Take this use case scenario:

I want to show a meta box on the page edit screen when a certain template is set.

To do the above I'd use some code like this:

    public static function add_meta_boxes( $post_type, $post )
        if( "page" != $post_type )

        if ( ! is_page_template('templates/with-solutions.php') )

        add_meta_box("bs_SolutionsMeta-meta", "Solutions", array( __CLASS__, "solutions_meta" ), "page", "normal", "low");

Unfortunately the above won't work as is_page_template() does an is_page() check in its function which will fail when run in admin.

I'd like to propose that the function be worked on to allow this function work in the admin some way.

I have found a work around and used:

        if ( 'templates/with-solutions.php' != get_page_template_slug( $post->ID ) )

for now but I'd love to see that function functional in admin.

Change History (3)

#1 @thee17
12 years ago

Using template tags does not make sense in the admin. I think your workaround is more along the proper method but I would use get_post_meta($post->id, '_wp_page_template');

#2 @l3rady
12 years ago

Ah yes it doesn't make sense in admin as it's a template tag. Didn't notice that at first glance.

Was just hoping that the function could be made more useful in more areas.

Admins please feel free to close if you feel this request is a non-starter.

#3 @SergeyBiryukov
12 years ago

  • Component changed from General to Template
  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

get_page_template_slug() indeed makes more sense in this case.

Note: See TracTickets for help on using tickets.