• Resolved amylkirst

    (@amylkirst)


    I’m trying to add a child theme, but I can’t enqueue my styles. The code provided by WP doesn’t work and I can’t find where you enqueue your stylesheet in the function theme.

    What do I need to do in my functions.php file to bring in my child theme?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The code provided by WP doesn’t work and I can’t find where you enqueue your stylesheet in the function theme.

    The codes that you saw on WP Codex didn’t work for Smallblog theme is because Smallblog loads its styles differently from the standard themes.

    Smallblog’s way of loading styles is actually the opposite of the standard themes. (I don’t know why the Smallblog theme author did that though; probably because he/she thought that it’d be fun to throw off novice developers or something along that line, haha.)

    .

    Smallblog parent theme’s style is set to load regardless of whether you enqueue it in your child theme or not.

    On the other hand, it won’t automatically load your child theme’s style.css. And if you put the parent-theme’s styles as a dependency of the child-theme’s styles in your child theme’s functions.php (like how the WP Codex instructed on the second way to enqueue), then the parent theme’s styles would still load after the child-theme’s styles, effectively overwriting the child-theme’s styles.

    That behavior is the opposite of any other standard theme.

    .

    So you’ll need to do the opposite of WP Codex’s instruction. WP Codex tells you to enqueue the parent theme’s styles. So the opposite of that would be to completely ignore the parent-theme’s styles and enqueue only the child theme’s styles, like this:

    <?php
    
    function smallblog_child_scripts() {
    	wp_enqueue_style( 'smallblog-child', get_stylesheet_directory_uri() . '/style.css' );
    }
    add_action( 'wp_enqueue_scripts', 'smallblog_child_scripts', 20 );
    
    ?>

    ^ Add that to your child theme’s functions.php file.

    Theme Author monkey-themes

    (@monkey-themes)

    Thank you very much ThePixelMe for your feedback and sharing of your view.

    @amylkirst plz let us know if you have any more questions.
    Cheers

    <?php

    function smallblog_child_scripts() {
    wp_enqueue_style( ‘smallblog-child’, get_stylesheet_directory_uri() . ‘/style.css’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘smallblog_child_scripts’, 20 );

    ?>

    Thanks so much! The PixelMe! This worked!

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