Home only first line of wp_enqueue_style gets executed
Reply: 2

only first line of wp_enqueue_style gets executed

Reinier Dekker
1#
Reinier Dekker Published in 2017-12-07 22:39:06Z

I'm trying to build a child theme for an existing theme someone else built. That theme uses multiple stylesheets and of course, I want the child theme to enqueue them all.

Strangely enough I noticed that that only the first line of the wp_enqueue_style() of the parent theme gets executed while the wp_enqueue_style() of the child theme does work.

I'm kinda stuck and I have no clue on how to make the child theme use all those stylesheets.

    function my_theme_enqueue_styles() {

    //parent style
    $parent_style = 'parent-style';

    //enqueue css of the parent theme
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/scripts/css/bootstrap.min.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/scripts/css/custom-login.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/scripts/css/font-awesome.min.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/scripts/css/font-dc-cash.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/scripts/css/font-dccash.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/scripts/css/hro-admin.css' );

    //enqueue css of the child theme
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

btw: I know that those css files dont't make any sense. Tell that to the original builder.

download link of the parent theme

Morfie
2#
Morfie Reply to 2017-12-07 23:12:52Z

The first parameter to wp_enqueue_style() needs to be unique. You are passing in $parent_style for everything. If you give them all unique names, maybe using $parent_style as a prefix, it should fix it.

Colin Cline
3#
Colin Cline Reply to 2017-12-07 23:19:06Z

Give first parameter a name, a unique one so in that way you can enqueue all of them.

Based on wordpress codex:
wp_enqueue_style( string $handle, string $src = '')

$handle (string) (Required) Name of the stylesheet. Should be unique.

function my_theme_enqueue_styles() {
    //parent style
    $parent_style = 'parent-style';

    //enqueue css of the parent theme
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/scripts/css/bootstrap.min.css' );
    wp_enqueue_style( 'custom_login', get_template_directory_uri() . '/assets/scripts/css/custom-login.css' );
    wp_enqueue_style( 'font_awesome', get_template_directory_uri() . '/assets/scripts/css/font-awesome.min.css' );
    wp_enqueue_style( 'font_dc_cash', get_template_directory_uri() . '/assets/scripts/css/font-dc-cash.css' );
    wp_enqueue_style( 'font_dccash', get_template_directory_uri() . '/assets/scripts/css/font-dccash.css' );
    wp_enqueue_style( 'hro_admin', get_template_directory_uri() . '/assets/scripts/css/hro-admin.css' );

    //enqueue css of the child theme
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') );
}

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319007 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO