Return the Template Name of Current WordPress Page

WordPress save the assignment in the post_meta table and so it is easy to get the template name with the default function to return post meta data – get_post_meta(). The key for the value is _wp_page_template.

On this point also a small hint: if you will, that you not find your key on the list of post meta keys on the custom fields, create a key with underline and start on the string and WordPress don’t list this key in select box; very useful for custom meta boxes on posts and pages.

$template_file = get_post_meta( get_the_ID(), '_wp_page_template', TRUE );





One response to “Return the Template Name of Current WordPress Page”

  1. […] WPEngineer gibt es einen kleinen Schnipsel, um den Namen des genutzten Templates herauszufinden und […]