Notes on WordPress Child Theme Development

I’ll write some notes on the sometimes dumb problems I meet while developing child themes. I won’t be verbose, I’ll just share the solutions that worked for me. Would be appreciated if you share a better one in the comments.

 


 

Problem: The parent’s style.css is not loading

Possible cause: forgotten Template: in the child style.css. The name to choose for Template field depends on the name of directory where the parent theme is. Case-sensitive.

Solution:

/*
Theme Name: uReport
Theme URI:
Description: Themerush Child Theme developed for news media.
Author: Shtrak!
Author URI: http://shtrak.eu/it/
Template: themerush
Version: 1.0.0
License: GNU General Public License
License URI: license.txt
*/

 


 

Problem: The child’s style.css doesn’t override the parent’s one

Possible cause: get_tempate_directory() is creating the problem, as in style.css is searched for in the parent directory not the child one, therefore s/template/stylesheet/.

Solution: When the style.css of the parent theme is included as it should – using wp_enqueue_style() in functions.php a working solution is to add action in the child’s functions.php to predefine the path to the style.css **sigh**


function child_theme_enqueue_styles() {
wp_enqueue_style( 'style', get_stylesheet_directory_uri().'/style.css' );
}
add_action( 'after_setup_theme', 'child_theme_enqueue_styles' );

But that’s quite stupid because if there are styles included originally after parent’s version of style.css the above will override them as well. rage.
I need to come up with different solution.

Oh well, solution:


function child_theme_enqueue_styles() {
wp_enqueue_style( 'style', get_stylesheet_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );

Simple as that. Conclusion: I’m an idiot.
Edit: It’s actually absolutely the same as the previous solution in the means of effects.

I actually ended up enqueuing the same styles as the parent’s theme in the same order and where i wanted to override I put get_stylesheet_directory_uri() instead of get_template_directory_uri() because there was some problem with the order of including therefore some previosly enqueued styles were not overridden.. I just.. **sigh**

Ahaaa, actually you just neet to change the handle parameter. dude..
At the end you don’t need to enqueue all the styles just enqueue your child styles with different handle. heh :3



Comments

Leave a Reply

Your email address will not be published. Required fields are marked *