Support » Developing with WordPress » Enqueuing another stylesheet

  • Hi there,

    I am trying to add a CSS file via my functions.php file, but the stylesheet is not loading.

    The file I would like to add is in ../themes/zigcy-lite-child/css/styles.min.css

    I am using this but it’s not working:

    <?php 
    	 add_action( 'wp_enqueue_scripts', 'zigcy_lite_child_enqueue_styles' );
    	 function zigcy_lite_child_enqueue_styles() {
     		  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); 
              wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/css/styles.min.css', array( $parent_style ) );
     		  } 
     ?>

    Cam anyone tell me what I am doing wrong?

    Many thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Please read the Child Theme section of the Theme Developer Handbook. I recently put more information than used to be there.

    Your code needs to use the same handle as the parent theme uses (not the generic ‘parent-style’) or it will be loaded twice, and you need to look in the parent theme code to see what the child theme needs to do.

    Anonymous User 18274256

    (@anonymized-18274256)

    Hi @thetoolman123,

    Here, I think you need to add a child theme’s style.css file in a root directory of the child theme instead of css directory. Once you will add it in root directory of the child theme then you need enqueue it from the root directory instead of css direcotry.

    I hope this will help for you.

    Regards,

    Thread Starter thetoolman123

    (@thetoolman123)

    Hi

    I already have the child’s CSS enqueued in the child directory with these lines:

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

    I basically just want to add another CSS file to the page.

    Thread Starter thetoolman123

    (@thetoolman123)

    Ok I worked it out… this is what I needed:

    	 add_action( 'wp_enqueue_scripts', 'zigcy_lite_child_enqueue_styles' );
    	 function zigcy_lite_child_enqueue_styles() {
     		  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); 
             wp_enqueue_style( 'px-icon-style', get_stylesheet_directory_uri() . '/css/styles.min.css' ); 
     		  } 

    Unless your parent theme is named ‘Parent’, you are loading its stylesheet twice. You should use the “View Source” option in your browser to see the stylesheets.

    And if the ‘px-icon-style’ stylesheet is dependent on any other sheet, you need to put the dependency parameter on it so that it comes out after it (since the child runs before the parent).

    Thread Starter thetoolman123

    (@thetoolman123)

    I see, thanks for replying.

    Do you know what the parameter is that I need to add?

    Thanks

    See my previous reply.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Enqueuing another stylesheet’ is closed to new replies.