You can get the filename of the page template that the post in the WordPress admin is set to using:

$page template = get_post_meta( $post->ID, '_wp_page_template', true );

The function below gets the filenameĀ of the page template, then returns true if it matches the desired page template, or false if not.This is useful if you want to run code in the WordPress admin only for posts that are set to use a particular page template. Just replace ‘abc-123.php’ with the filename of the template you want to check against.

Here’s a more general version of that function that allows you to pass in the filename of a particular page template to check against:

Leave a reply

Your email address will not be published. Required fields are marked *