Digital experiences for all disciplines
New Landing › How can we help? › General › Feedback & Suggestions › Help needed with child theme
New Landing › How can we help? › General › Feedback & Suggestions › Help needed with child theme
- This topic has 5 replies, 3 voices, and was last updated 9 years by Rui Guerreiro – SUPPORT.
-
Posted in: Feedback & Suggestions
-
March 16, 2015 at 1:38 pm #157728
Hi, I need help setting up a child theme. As http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme states, the desired way to use child themes “is to enqueue the parent and child theme stylesheets”. I’ve followed the directions there but noticed i.e. the parent theme’s webfonts were not displayed correctly (not having declared any ‘overrides’ yet). Then I took a look into the child theme you provided and noticed it imports the parent’s style.css file. So, my question would be: What is the proposed method of getting the child theme to work properly? Is there any particular reason why the suggested WP method of enqueing the stylesheets isn’t supported? Or am I doing something wrong here? Thanks in advance. Lars
March 16, 2015 at 2:18 pm #157744Hi,
Please remove your child theme and use attached child theme.
Thanks
MohammadAttachments:
You must be logged in to view attached files.March 16, 2015 at 2:20 pm #157746Hi Mohammad, thanks for fast reply. My point is that @import(“parent.css”) is not best practice. What I am trying to achieve is what is outlined here: http://wordpress.stackexchange.com/questions/163301/versioning-import-of-parent-themes-style-css
March 16, 2015 at 2:49 pm #157767Hi,
Try to add the code below to your functions.php of your child theme.
Also delete/comment the import inside the style.cssadd_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); }
-Rui
March 16, 2015 at 2:57 pm #157778Hi Rui, OMG you guys answer so quick. Great! // I tried your suggestion already, but that leads to duplicate styles.css files. I now ended up doing this in my child theme’s functions.php:
The only downside is that I had to add a dependency to the bootstrap.css otherwise the styles.css files were printed BEFORE bootstrap’s css …
Do you see any obstacles in doing so?
Thanks!
<?php // Enqueue the parent and child theme stylesheets // See http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme // First, dequeue the parent stylesheet, otherwise it is duplicated // Dante uses the styles.css stylesheet as "sf-main-css", so unqueue it function theme_dequeue_styles() { wp_dequeue_style(array('sf-main', 'sf-main-css')); wp_deregister_style( array('sf-main', 'sf-main-css')); } // 99999 means really high priority add_action('wp_enqueue_scripts', 'theme_dequeue_styles', 99999); // Now enqueue the child theme's stylesheet depending on the parent's // Note that wp_register_style() is NOT needed if you use fully qualified wp_enqueue_style() function theme_enqueue_styles() { wp_enqueue_style( 'dante-parent-style', get_template_directory_uri() . '/style.css', array('bootstrap') ); wp_enqueue_style( 'mokik-child-style', get_stylesheet_directory_uri() . '/style.css', array('dante-parent-style') ); } add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); ?>
March 16, 2015 at 11:37 pm #157942Don’t see any obstacle. If it works that’s great.
-Rui -
Posted in: Feedback & Suggestions
You must be logged in and have valid license to reply to this topic.