Tagged: child theme, css
This topic contains 9 replies, has 5 voices, and was last updated by Support 1 year, 2 months ago.
- AuthorPosts
- September 19, 2017 at 7:08 am #119180
Tried creating a child theme through various plugins, but the error always was that the CSS was not loaded.
So following the official guide – https://codex.wordpress.org/Child_Themes#Creating_a_Child_Theme_from_an_Unmodified_Parent_Theme
What I know is, create a new folder for the child theme, and create a style.css file:/* Theme Name: Tyche child Theme URI: http://example.com/ Description: Child Theme Author: John Doe Author URI: http://example.com Template: tyche Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: tyche-child */
Then, create a functions.php file with:
<?php function my_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 ), wp_get_theme()->get('Version') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); ?>
But when activating the child theme, no CSS is loaded.
- This topic was modified 1 year, 5 months ago by
svgr.
September 19, 2017 at 11:17 am #119240Hello there,
I hope you are doing well today.
Have you tried the following plugin to create a child theme?
https://wordpress.org/plugins/child-theme-configurator/
Does this issue appear when you activate the parent theme?
Best Regards,
SupportSeptember 19, 2017 at 12:17 pm #119250Yes, I tried that plugin and 3 other popular plugins for creating child themes.
This issue does not appear when activating the parent theme.September 19, 2017 at 1:46 pm #119315The problem is that Tyche stores its CSS files in a different directory in multiple files:
tyche/assets/cssSo how do I edit my child theme’s function.php so I include all styles from /assets/css/?
November 30, 2017 at 1:51 pm #135050Change in functions.php ‘/style.css’ in ‘/assets/css/style.css’ .
December 1, 2017 at 1:25 pm #135195Hello there,
@wimforever Thanks for helping out with that solution.
@svgr Please let us know if the solution provided helped.Best Regards,
SupportDecember 8, 2017 at 10:06 pm #136297I think I have found the solution. Maybe very straightforward, but it works for me. I have used the plugin Child Theme Configurator. Unlike default wordpress themes, Tyche child css did not work. So I copied whole folder ‘assets’ into the Tyche child directory next to style.css and functions.php. It works!
December 8, 2017 at 10:12 pm #136298Ok, ok – @wimforever solution works as well 🙂
December 9, 2017 at 10:10 am #136334I did it next way:
add_action('wp_enqueue_scripts', [$this, 'enqueues']); public function enqueues() { // Replace Google fonts wp_dequeue_style('google-fonts'); wp_enqueue_style('google-fonts', '//fonts.googleapis.com/css?family=Roboto|Tinos&subset=cyrillic'); /** * START * Parent theme code * * @see Tyche::enqueues */ wp_enqueue_style('tyche', get_stylesheet_uri()); $scheme = get_theme_mod('tyche_color_scheme', 'red'); if ('red' !== $scheme) { wp_enqueue_style('tyche-style', get_template_directory_uri() . '/assets/css/style-' . sanitize_key($scheme) . '.css'); } else { wp_enqueue_style('tyche-style', get_template_directory_uri() . '/assets/css/style.css'); } $color = get_theme_mod('header_textcolor', '#ffffff'); if ('#ffffff' === $color) { $custom_css = ' .site-header .site-title{ color: #"' . esc_html($color) . '"; }'; wp_add_inline_style('tyche-style', $custom_css); } /** END */ // Load child theme styles wp_enqueue_style('tychejulia-style', get_stylesheet_directory_uri() . '/style.css', ['tyche-style']); }
Mess with
$color
looks unnecessary but I put it anyway.December 22, 2017 at 11:40 am #138446Hello @svgr,
Please let us know if any of the solutions that the member provided helped.
@pirouetti @okto @wimforever Thanks for adding your solutions.
Best Regards,
Support - This topic was modified 1 year, 5 months ago by
- AuthorPosts
The topic ‘How to create child theme’ is closed to new replies.