• 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?

  • The topic ‘How can I make is_page_template() function workable in child theme?’ is closed to new replies.