css - How to enqueue stylesheets in child-theme functions.php?

admin2025-01-08  3

I know this topic is old hat, but I still got issues with that. I use the elementor child-theme and try to enqueue the following stylesheets

  1. hello-child-theme-folder: style.css
  2. hello-child-theme/assets/css: style.css
function hello_elementor_child_enqueue_scripts() {
            wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', ['hello-elementor-theme-style',],'1.0.0');
            wp_register_style( 'test', get_template_directory_uri() . '/assets/css/style.css' );
            wp_enqueue_style( 'test' ); 
        }
add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts' );

I tried several other ways like described here: How Can I Use A Child Theme Effectively When Parent's CSS Is Located in a 'CSS folder'?

If I use this standard, my page gets blank:

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

I know this topic is old hat, but I still got issues with that. I use the elementor child-theme and try to enqueue the following stylesheets

  1. hello-child-theme-folder: style.css
  2. hello-child-theme/assets/css: style.css
function hello_elementor_child_enqueue_scripts() {
            wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', ['hello-elementor-theme-style',],'1.0.0');
            wp_register_style( 'test', get_template_directory_uri() . '/assets/css/style.css' );
            wp_enqueue_style( 'test' ); 
        }
add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts' );

I tried several other ways like described here: How Can I Use A Child Theme Effectively When Parent's CSS Is Located in a 'CSS folder'?

If I use this standard, my page gets blank:

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
Share Improve this question asked Nov 25, 2020 at 15:07 ChrizzlyChrizzly 34 bronze badges 1
  • 1 Does this answer your question? Enqueue styles properly in a child theme and stylesheets location – Deepak Kamat Commented Nov 25, 2020 at 17:42
Add a comment  | 

1 Answer 1

Reset to default 0

get_template_directory_uri always refers to the parent theme. get_stylesheet_directory_uri refers to the currently active theme, which in this case is the child theme.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266372a1115.html

最新回复(0)