Up to 50 percent off

Child Theme

This topic contains 8 reply and 6 voices, and was last updated by Larry 9 years, 8 months ago
Viewing 8 Posts - 1 through 8 (of 8 total)
Author Posts
April 22, 2014 at 1:15 am 19198
Larry 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
------------------------------------------------------- */
April 22, 2014 at 6:08 am 19205
Marita Marita

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

April 22, 2014 at 7:07 am 19208
Mahi Mahi

Make sure you put right version number of dokan theme?

April 22, 2014 at 7:16 am 19209
Marita Marita

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 ); 
April 22, 2014 at 12:41 pm 19216
Sk Sk

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.

April 23, 2014 at 8:39 pm 19301
Simon Simon

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'); 

}
February 13, 2015 at 7:50 am 36632
Gabriel Gabriel

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

February 13, 2015 at 7:53 am 36633
Gabriel Gabriel

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' );
}
March 3, 2015 at 5:56 pm 38091
Larry Larry

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 8 Posts - 1 through 8 (of 8 total)