How can I make is_page_template() function workable in child theme?
-
I am using a child theme.
I want ‘no-sidebar.css’ to be loaded if ‘page-nosidebar.php’ is loaded. So I wrote the following code. It is not working. But it works in the Parent Theme:function no_sidebar_style(){
if (is_page_template(‘page-templates/page-nosidebar.php’)) {
wp_enqueue_style( ‘no-sidebar-style’ , get_stylesheet_directory_uri().’/css/no-sidebar.css’);
}
}
add_action( ‘wp_enqueue_scripts’, ‘no_sidebar_style’, 19);If I write is_page_template(get_stylesheet_directory_uri().’/page-templates/page-nosidebar.php’) instead of (is_page_template(‘page-templates/page-nosidebar.php’) as below, it also do not work:
function no_sidebar_style(){
if (is_page_template(get_stylesheet_directory_uri().’/page-templates/page-nosidebar.php’)) {
wp_enqueue_style( ‘no-sidebar-style’ , get_stylesheet_directory_uri().’/css/no-sidebar.css’);
}
}
add_action( ‘wp_enqueue_scripts’, ‘no_sidebar_style’, 19);Please advise me, how can I make the code workable?
-
It looks like you are working with a self-hosted WordPress.org site instead of the WordPress.com-hosted version supported here.
Learn more about the differences between WordPress.com and WordPress.org:
https://en.support.wordpress.com/com-vs-org/I would recommend asking on the WordPress.org support forums for assistance with this. The forums are completely separate from each other, so you will need to register an account there if you haven’t done so already.
- The topic ‘How can I make is_page_template() function workable in child theme?’ is closed to new replies.