I'm trying to add styles and scripts to specific template, But it's not working.
In functions.php
I tried:
if( is_page_template('file.php') ){}
if( is_page_template( get_template_directory() . 'file.php') ){}
if( is_page_template( get_template_directory_uri() . 'file.php') ){}
When I searched for that, Some answers suggested using wp_reset_query();
, Before the condition, but didn't work too.
Also others suggested using the condition inside a function:
function test(){
if( is_page_template( get_stylesheet_directory() . 'file.php' ) ){
wp_enqueu_script( 'custom-script', get_template_directory_uri() . 'js/custom.js' );
}
}
add_action( 'wp_enqueue_scripts', 'test' );
Nothing worked with me.
In file.php
:
<?php
/*
Template Name: testing
*/
?>
I created a page and used that template.
What's the problem?