I’m developing now a wordpress theme, and wondering if there is an option to know if a template file is being used by a page?
I need the link to that page…
thanks!
Leave a Reply
You must be logged in to post a comment.
I’m developing now a wordpress theme, and wondering if there is an option to know if a template file is being used by a page?
I need the link to that page…
thanks!
You must be logged in to post a comment.
The function get_page_template_slug( $post_id ) will return the slug of the currently assigned page template (or an empty string if no template has been assigned – or false if the $post_id does not correspond to an actual page). You can easily use this anywhere (in The Loop, or outside) to determine whether any page has been assigned a page template.
is_page_template(); function will return true when template is used. you can also pass file name to check if particular template is applied or not.
There is one more method too. You can use get_post_meta to get value of applied template.
The previously suggested answer will not get you what you want. It will just show you in the current page or a page you specify is using the template not find any pages that are using it.
If you want to actually search to see if any pages are using a template you can make a query. meta_query isn’t the most efficient/fastest but depending on what you are building probably won’t be an issue.