New Landing How can we help? General Feedback & Suggestions Help needed with child theme

Viewing 6 posts - 1 through 6 (of 6 total)
  • #157728
    larsgrau
    Member
    Post count: 4

    Hi, I need help setting up a child theme. As http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme states, the desired way to use child themes “is to enqueue the parent and child theme stylesheets”. I’ve followed the directions there but noticed i.e. the parent theme’s webfonts were not displayed correctly (not having declared any ‘overrides’ yet). Then I took a look into the child theme you provided and noticed it imports the parent’s style.css file. So, my question would be: What is the proposed method of getting the child theme to work properly? Is there any particular reason why the suggested WP method of enqueing the stylesheets isn’t supported? Or am I doing something wrong here? Thanks in advance. Lars

    #157744
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please remove your child theme and use attached child theme.
    Thanks
    Mohammad

    Attachments:
    You must be logged in to view attached files.
    #157746
    larsgrau
    Member
    Post count: 4

    Hi Mohammad, thanks for fast reply. My point is that @import(“parent.css”) is not best practice. What I am trying to achieve is what is outlined here: http://wordpress.stackexchange.com/questions/163301/versioning-import-of-parent-themes-style-css

    #157767
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Try to add the code below to your functions.php of your child theme.
    Also delete/comment the import inside the style.css

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

    -Rui

    #157778
    larsgrau
    Member
    Post count: 4

    Hi Rui, OMG you guys answer so quick. Great! // I tried your suggestion already, but that leads to duplicate styles.css files. I now ended up doing this in my child theme’s functions.php:

    The only downside is that I had to add a dependency to the bootstrap.css otherwise the styles.css files were printed BEFORE bootstrap’s css …

    Do you see any obstacles in doing so?

    Thanks!

    <?php
    
    // Enqueue the parent and child theme stylesheets 
    // See http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme 
    
    // First, dequeue the parent stylesheet, otherwise it is duplicated
    // Dante uses the styles.css stylesheet as "sf-main-css", so unqueue it
    function theme_dequeue_styles() {
        wp_dequeue_style(array('sf-main', 'sf-main-css'));
        wp_deregister_style( array('sf-main', 'sf-main-css'));
    }
    
    // 99999 means really high priority
    add_action('wp_enqueue_scripts', 'theme_dequeue_styles', 99999);
    
    // Now enqueue the child theme's stylesheet depending on the parent's
    // Note that wp_register_style() is NOT needed if you use fully qualified wp_enqueue_style()
    	
    function theme_enqueue_styles() {
        wp_enqueue_style( 'dante-parent-style', 
        	get_template_directory_uri() . '/style.css', 
        	array('bootstrap')
        );
        wp_enqueue_style( 'mokik-child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array('dante-parent-style')
        );
    }
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    	
    	
    ?>
    #157942
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Don’t see any obstacle. If it works that’s great.
    -Rui

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register