• I’ve made a child theme and I’m trying to enqueue my stylesheet, but it doesn’t seem to be working.

    Here is my code:

    function child_scripts_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css', array() );
    }
    add_action( 'wp_enqueue_scripts', 'child_scripts_styles' );

    I just don’t see what’s wrong.
    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • That appears to be correct. Can’t see any reason why it wouldn’t work.

    Simple, I know, but verify that the child theme is activated.

    Is your code in the child theme’s functions.php file or somewhere else?

    How is the parent theme enqueuing its stylesheet? Is it doing anything out of the ordinary?

    Thread Starter Cristi Roberts

    (@cristi-roberts)

    Thank you for answering. My child theme has been activated. The childs functions.php is in my child theme. I have the css file, a header.php, footer.php and front-page.php in my child theme. Here is my parent enqueue
    code:
    <?php

    function theme_styles() {
    wp_enqueue_style( ‘bootstrap_css’ , get_template_directory_uri() . ‘/css/bootstrap.min.css’ );
    wp_enqueue_style( ‘main_css’ , get_template_directory_uri() . ‘/style.css’ );
    }
    add_action( ‘wp_enqueue_scripts’ , ‘theme_styles’ );

    function theme_js() {

    global $wp_scripts;

    wp_register_script( ‘html5_shiv’, ‘https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js&#8217;, ”, ”, false );
    wp_register_script( ‘respond_js’, ‘https://oss.maxcdn.com/respond/1.4.2/respond.min.js&#8217;, ”, ”, false );

    $wp_scripts->add_data( ‘html5_shiv’, ‘conditional’, ‘lt IE 9’ );
    $wp_scripts->add_data( ‘respond_js’, ‘conditional’, ‘lt IE 9’ );

    wp_enqueue_script( ‘bootstrap_js’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array(‘jquery’), ”, true );
    wp_enqueue_script( ‘theme_js’, get_template_directory_uri() . ‘/js/theme.js’, array(‘jquery’, ‘bootstrap_js’), ”, true );
    }
    add_action( ‘wp_enqueue_scripts’, ‘theme_js’ );
    `
    Cristi

    Thread Starter Cristi Roberts

    (@cristi-roberts)

    I changed it to this and it works:

    function theme_enqueue_styles() {
    
        $parent_style = 'parent-style';
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style )
        );
    }
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘enqueue child theme’ is closed to new replies.