I'm attempting to load a couple of scripts based on the template in use. However, the is_page_template is not activating. From my functions.php in the child theme I have:

function sectionDescription (){
if (is_page_template('taxonomy-tableofcontents.php')){
add_action('wp_enqueue_scripts', 'sectionDescription');

I can't see a syntax problem. I'm assuming that you can use this conditional in the functions file to control the enqueueing of scripts, I can't find anything to the contrary. As I've looked around at other examples my formatting seems to be correct.

I'd appreciate any suggestions on a possible source of the problem.

Note: The scripts are registered in another section of the functions file. When I first loaded the scripts I had the registration and enqueue together and loading on every page. This worked as expected so I don't doubt the syntax of the registration and enqueueing.

I added some test php to the page to test the activation of the is_page_template and it indicates that the conditional statement is not working.

I'm thinking that I don't understand how to use this conditional but I can't see what's missing.

  • Sorry, but taxonomy-tableofcontents.php is for displaying the 'tableofcontents' taxonomy archive? – gmazzap Aug 1 '13 at 4:49

is_page_template only works for templates belonging to the page post type. It appears your template is for a custom taxonomy, so you want to instead check if is_tax.

if( is_tax( 'tableofcontents' ) )

You can use filter template_include.

For example:

add_filter('template_include', 'theme_check_page', 1, 1);
function theme_check_page($template) 
    echo substr($template,strripos($template,'/')+1); // index.php, single.php and other
    return $template;
  • I don't see how to get to the conditional from this. I'm not familiar with this filter but my short research suggests its used to control the template in use. Wouldn't I still need to add a conditional statement for the taxonomy in use? – dorich Aug 1 '13 at 15:38
  • Using this filter you can get title of the file and add this value into $GLOBAL and use anywhere you want. – Vladimir Aug 2 '13 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.