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

Comments are closed.

One comment

One pingback

  1. Adventskalender vom 11. Dezember « F-LOG-GE