I just learnt about creating child themes from the Codex , it says to add
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
and
function theme_enqueue_styles() {
$parent_style="parent-style";
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
in my child theme’s functions.php
file but it did not address the issue when our parent theme has more then one style sheet(.css files
). (In my case twenty-fourteen theme has two style.css
and rtl.css
) and two more in /css folder named editor-style.css
and ie.css
So what I have to change in the code above to load both stylesheets
.
I have gone through this question but it did not address my issue.
1 Answer
Twenty fourteen loads its stylesheets differently in that it made the main stylesheet dependant on the genericon stylesheet, and I’m sure that this is the problem you are experiencing. (if not, please update your question with proper details)
You can change how you enqueue your style in the first block of code as follow
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array( 'genericons' ) );
EDIT
You have a misunderstanding about how certain stylesheets are loaded. The child theme loads all stylesheets from the parent except the parent stylesheet. That is how the system was build. Now, there are stylesheets that are not loaded by the theme, but by WordPress by default
-
editor-style.css
get loaded automatically on the TinyMCE editor. Please see the codex for a full explanation -
rtl.css
only gets loaded when the website is set to a rtl language. On ltr languages like English, the stylesheet is not loaded. This is also done by default by WordPress. Just a note, why would you want to load your rtl stylesheet on a ltr site. It is a waste of resources for one -
ie.css
The ie stylesheet is only loaded when the current browser is IE8 or older. That is the whole purpose of the ie stylesheet. IE8 and older does not support media queries, so other styles needs to be loaded on that browser.
The only code you need in your child functions.php is the following
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array( 'genericons' ) );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( 'parent-style' )
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );