2

I'm using Knowall theme for WordPress. I've developed a child theme with the following code placed in my style.css file in my child theme's folder:

/*
 Theme Name: KnowAll Child Theme
 Theme URI: help.mysite.com
 Description: Help site
 Author: myurl.com
 Template: knowall
 Version: 1.0
 */
@import url("../knowall/css/style.css");

This works (child theme is shown in WordPress) but created the following broken link:

http://help.mysite.com/wp-content/themes/knowall-child/css/style.css?ver=4.8

So it looks like it's trying to locate the core Knowall style.css from within the child theme rather than the parent folder.

I've 'fixed' this by importing the parent style.css directly into the child theme folder. I've also had to do the same for the 'img' folder.

How can I re-target these assets so it finds them in the parent theme? I don't want to have to re-import assets to the child theme every time I update Wordpress...

1

There is most likely some issues about using get_template_directory_uri() or get_stylesheet_directory_uri().

According to WordPress Code reference:

get_template_directory_uri() function returns the URL to the root theme. If a child theme is used and you want to return the URL to the current child theme, use get_stylesheet_directory_uri() instead.

Also, it is noted that importing the parent CSS file is not a good practice anymore:

Note that the previous method was to import the parent theme stylesheet using @import: this is no longer best practice, as it increases the amount of time it takes style sheets to load. The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme's functions.php.

So, what you have to do is to enqueue the style by using the following code in your child theme's functions.php file:

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

}

And then enqueue your own CSS files if there is any.

0

I think so I understand you wrong or you don´t know 100% for what you use a child-theme.

A child theme is a theme that inherits the functionality and styling of another theme, called the parent theme. Child themes are the recommended way of modifying an existing theme.

https://codex.wordpress.org/Child_Themes

You don´t need to import the parent style in your child. In style.css you include your own coded css.

Your folder structur are: wp-content/theme/knowall-child/css/style.css and in css/style.css is your custom css code.

Switch your style.css to:

/*
Theme Name: KnowAll Child Theme
Theme URI: help.mysite.com
Description: Help site
Author: myurl.com
Template: knowall
Version: 1.0
*/
@import "css/style.css";

That should solve your prob.

  • 1
    According to Codex, importing the style from parent is not a good practice. – Jack Johansson Jun 13 '17 at 12:04
0

Write this code in you functions.php

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

}

0

Jack Johansson is on point. However, since you don't seem very in the know with this stuff, One-Click Child Theme can automate the process of creating child themes and follows best practices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.