How to Get the Page Template Name Like in Block Editor?
-
Hi everyone,
I’m trying to retrieve the current page’s template name the same way it’s shown in the Block Editor. In the editor, I can get it using:
wp.data.select('core/edit-site').getEditedPostId();
For example, it returns:
- Blog Home template:
"twentytwentyfour//home"
- Single Posts template:
"twentytwentyfour//single"
- Pages template:
"twentytwentyfour//page"
However, when trying to get the template name via PHP, I haven’t found a reliable way.
I’ve tried several approaches, butglobal $template
always returns:/opt/web/public/wp-includes/template-canvas.php
Regardless of the hook I use.
Is there a way to get the actual template name in PHP, similar to how it’s retrieved in the Block Editor?
Any help is appreciated!
- Blog Home template:
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.