Home Forums Theme Support Dokan Child Theme

This topic is: not resolved

This topic contains 8 replies, has 6 voices, and was last updated by  Larry 4 years, 2 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #19198

    Marita
    Member
    Post count: 7

    I created a child theme using this code below. Works fine – except none of the styles i add to it are being recognized. I saw in another thread you offered to add a script to the functions.php file – but that would defeat the purpose of a child theme – because when i update the theme it would overwrite the functions file.

    Is there any method of creating a child theme? I feel like the ability to create a Child theme is a basic requirement for any wordpress themes.

    /*
     Theme Name:     Dokan Child Theme
     Description:    Child Theme
     Template:       dokan
     Version:        1.0.0
    */
     
    @import url("../dokan/style.css");
     
    /* Theme customization starts here
    ------------------------------------------------------- */
    #19205

    Marita
    Member
    Post count: 7

    Update: all other php files overwrite sucessfully as a child theme- just the css doesnt.

    #19208

    Mahi
    Member
    Post count: 1555

    Make sure you put right version number of dokan theme?

    #19209

    Marita
    Member
    Post count: 7

    No i think i figured it out. The theme is coded in a way to not allow child themes to overwrite the parent style. I changed some code in function.php in the enqueue scripts section.

    Basically, $template_directory needed to be changed to $stylesheet_directory. By using template_directory, the child theme is still telling it to look for the parent stylesheet. See below:

    This solution still requires you to change the function.php file, so technically its not a true child theme.

    A less intrusive solution i think is just to add a customstyle.css in the header.php because when the theme is updated, all it will require you to do is add that line of code back to the header.

    Thoughts?

       /**
         * Enqueue scripts and styles
         *
         * @since Dokan 1.0
         */
    
       function scripts() {
           ADDED THESE:
            $stylesheet_directory = get_stylesheet_directory_uri();
    
            wp_enqueue_style( 'style', $stylesheet_directory . '/style.css', false, null ); 
    #19216

    Sk
    Moderator
    Post count: 371

    hello Marita,

    you should use add action for your function scripts and give it a greater priority than dokan function dose. then your style will over-wright dokan style.
    you could use:
    add_action( 'wp_enqueue_scripts', 'scripts', 99);

    Thank you.

    #19301

    Simon
    Member
    Post count: 58

    Until Wedev fixes their functions.php you'll need to dequeue and enqueue the styles.

    In your child theme's function.php you need to dequeue the style.css from the parent theme and then enqueue the style.css you have in your child theme. See code below. This assumes you have added a style.css to the root of your child theme and that the style sheet has the tag for version 1.0.3.

    /* Remove default stylesheet */ 
    add_action('wp_enqueue_scripts', 'bwf_remove_scripts');
    
    function bwf_remove_scripts(){
        wp_dequeue_style( 'style' );
    }
    
    /* Add replacement stylesheet */
    add_action('wp_enqueue_scripts', 'bwf_add_scripts');
    function bwf_add_scripts(){
    
        /* main style */
        wp_enqueue_style( 'dokan-stylesheet', get_stylesheet_uri(), array(), '1.0.3', 'all'); 
    
    }
    #36632

    Gabriel
    Member
    Post count: 15

    Hi,

    What code do I need in my child theme style.css for Simon's code to dequeue and enqueue functions.php?

    In my child theme I have the following for my style.css:

    /*
    Theme Name:     dokan-child
    Description:    Dokan child theme
    Author:         admin
    Template:       dokan
    
    (optional values you can add: Theme URI, Author URI, Version)
    */
    
    @import url("../dokan/style.css");

    I feel like I need the Version, etc…what else do I need to make Simon's code work?

    Thanks!
    -Gabe

    #36633

    Gabriel
    Member
    Post count: 15

    Could we just use this to enqueue the child theme? Or do I need to use Simon's code to dequeue and then enqueue in functions.php in the Dokan child theme?

    // Allows child theme to get info from parent theme 
    add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style' );
    function enqueue_parent_theme_style() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    #38091

    Larry
    Member
    Post count: 22

    This worked for me, none of the other fixes above it did… Thanks Simon

    /* Remove default stylesheet */ 
    add_action('wp_enqueue_scripts', 'bwf_remove_scripts');
    
    function bwf_remove_scripts(){
        wp_dequeue_style( 'style' );
    }
    
    /* Add replacement stylesheet */
    add_action('wp_enqueue_scripts', 'bwf_add_scripts');
    function bwf_add_scripts(){
    
        /* main style */
        wp_enqueue_style( 'dokan-stylesheet', get_stylesheet_uri(), array(), '1.0.3', 'all'); 
    
    }
Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Child Theme’ is closed to new replies.