get page templates

Checking for get_page_templates() in the core, I found a workaround that doesn’t break the theme like:

Fatal error: Call to undefined function get_page_templates()

I’m using this just after <body> and works ok:

$templates = wp_get_theme()->get_page_templates();

foreach ( $templates as $template_name => $template_filename ) 
{
    echo "$template_name ($template_filename)<br />";
}

Leave a Comment