Correct code in functions.php for style.css

This topic contains 4 reply and 3 voices, and was last updated by Marita 10 years, 6 months ago
Viewing 4 Posts - 1 through 4 (of 4 total)
Author Posts
April 23, 2014 at 5:40 am 19259
Marita I've seen this mentioned in another thread, but can you please update line 269 in the functions.php file. Change from: wp_enqueue_style( 'style', $template_directory . '/style.css', false, null ); Change to: wp_enqueue_style( 'dokan-stylesheet', get_stylesheet_uri(), array(), '1.0.3', 'all'); This makes it easy to create a child theme, which will have a style.css to override the style.css in the parent dokan theme. All that has to be at the top of the child theme's style.css is:
*
Theme Name: Dokan Child Theme
Theme URI: http://wedevs.com/dokan
Description: This is a child theme for Dokan
Author: We Devs
Author URI: http: //www.wedevs.com/
Template: dokan
Version: 1.0.3
*/

@import url("../dokan/style.css");
Then only the version number needs to be updated in the parent style.css, the child style.css, and the functions file when updating Dokan.
April 23, 2014 at 3:05 pm 19278
Tareq Hasan Tareq Hasan

Hello Simon,

Thanks for the post. Although we are not using style.css for Dokan instead /assets/css/style.css. One thing can be done is on Dokan theme is to register the stylesheet first and then enqueue it. Then if you don’t need the styles in the child theme, you can dequeue the stylesheet from the child theme.

April 23, 2014 at 6:21 pm 19294
Simon Simon

Hi Tareq,

Technically you are using the main style.css as it’s required by WordPress. Just because you’ve decided to add additional stylesheets does not mean that style.css is not enqueued — as can be seen on line 269 of your functions.php.

Please see this page: https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

As a workaround, I’ve already dequeued line 269 in my child theme’s function.php file, but there is no need for this if you could make the simple fix. This will make it easier for you, and others, to create their child theme.

Here’s what I’m currently doing in the functions.php in my child-theme.

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

}
April 23, 2014 at 8:55 pm 19302
Simon Simon

Additional details on how child themes work. https://codex.wordpress.org/Child_Themes

April 25, 2014 at 2:47 am 19360
Marita Marita

Simon i agree that changing the functions.php to make child theme support standard can easily be done – but i find this just as easy to create a functions.php in my child theme and add this code.

All that its doing is loading the style.css from my child theme as the last style in the wp_enqueue_scripts function.

<?php

function theme_name_scripts() {
    wp_enqueue_style( 'yellow-ribon', get_stylesheet_uri() );
}
 
add_action( 'wp_enqueue_scripts', 'theme_name_scripts', 99 );

?>
Viewing 4 Posts - 1 through 4 (of 4 total)