• Resolved script2see

    (@script2see)


    Hi. I’m currently finishing up styling a child theme of Twenty Twenty-Four, and I’m not sure of the code that I should use to enqueue the child theme’s CSS stylsheet.

    The child themes page of WordPress Developer Resources provides two versions of the code:

    Version 1:

    add_action( 'wp_enqueue_scripts', 'grand_sunrise_enqueue_styles' );
    
    function grand_sunrise_enqueue_styles() {
    	wp_enqueue_style( 
    		'grand-sunrise-style', 
    		get_stylesheet_uri()
    	);
    }

    Version 2:

    add_action( 'wp_enqueue_scripts', 'grand_sunrise_enqueue_styles' );
    
    function grand_sunrise_enqueue_styles() {
    	wp_enqueue_style( 
    		'grand-sunrise-parent-style', 
    		get_parent_theme_file_uri( 'style.css' )
    	);
    }

    I was going to use the following code for my child theme, hlcbpc, but I’m not sure if it’s correct;

    add_action( 'wp_enqueue_scripts', 'hlcpbc_styles' );
    
    function hlcpbc_styles() {
    	wp_enqueue_style( 
    		'hlcpbc-style', 
    		get_stylesheet_uri( 'style.css' )
    	);
    }

    So, my child theme’s functions.php file would have the following:

    <?php
    /**
     * hlcpbc functions and definitions
     *
     * @link https://developer.www.ads-software.com/themes/basics/theme-functions/
     *
     */
    
    /**
     * Register block styles.
     */
    
    add_action( 'wp_enqueue_scripts', 'hlcpbc_styles' );
    
    function hlcpbc_styles() {
    	wp_enqueue_style( 
    		'hlcpbc-style', 
    		get_stylesheet_uri( 'style.css' )
    	);
    }

    Thanks in advance for your help.

    • This topic was modified 9 months, 2 weeks ago by script2see.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Just implement one approach in your functions file, then refresh your browser and View Source of the page, and the click on the child theme CSS link that is output in the source. If it’s not right, it will throw a 404 error.

    Personally I would use this,

    add_action( 'wp_enqueue_scripts', 'hlcpbc_styles' );
    
    function hlcpbc_styles() {
    	wp_enqueue_style( 
    		'hlcpbc-style', 
    		get_stylesheet_uri( 'style.css' )
    	);
    }

    Thread Starter script2see

    (@script2see)

    Thank you very much, corrinarusso. I really appreciate your help.

    Moderator bcworkz

    (@bcworkz)

    The style.css for the 2024 theme has no useful CSS code. It’s only there to provide generic theme information where WP expects to find it. You needn’t be concerned how the parent theme enqueues its style.css file. Just enqueue your own child’s style.css file on its own without concern for the parent. Like corrinarusso suggested.

    Thread Starter script2see

    (@script2see)

    Thanks, bcworkz.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Enqueuing Stylesheet of Child Theme’ is closed to new replies.