dcd0181 dcd0181 - 5 months ago 45
PHP Question

Checking for page templates in child theme

I have a simple problem I'm hoping someone can shed some light on. I have a child theme with a custom page template and I'm simply trying to check weather or not the template is in use. Under normal circumstances, I would have just used the

function, however it doesn't seem to be working with child themes. I've tried the following

//do something..

as well as

//do something..

Neiter works and I was hoping there is a more elegant solution than using
to check for URLs. I can't imagine there not being a function for this seeing as this seems like a common task. I believe the problem is the difference between template and stylesheet directories. Is it possible to use Wordpress to check for page templates located in a child theme?

Thanks in advance!


Reference this WP Codex page: http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

Use get_stylesheet_directory_uri instead. This should work:

is_page_template(get_stylesheet_directory_uri() . '/template-custom-fullwidth.php')
    //do something..