How to create child theme

Tried creating a child theme through various plugins, but the error always was that the CSS was not loaded.
So following the official guide - Child Themes « WordPress Codex
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.

Hello there,

I hope you are doing well today.

Have you tried the following plugin to create a child theme?

Does this issue appear when you activate the parent theme?

Best Regards,
Support

Yes, I tried that plugin and 3 other popular plugins for creating child themes.
This issue does not appear when activating the parent theme.

The problem is that Tyche stores its CSS files in a different directory in multiple files:
tyche/assets/css

So how do I edit my child theme’s function.php so I include all styles from /assets/css/?

Change in functions.php ‘/style.css’ in ‘/assets/css/style.css’ .

Hello there,

@wimforever Thanks for helping out with that solution.
@svgr Please let us know if the solution provided helped.

Best Regards,
Support

I 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!

Ok, ok - @wimforever solution works as well :slight_smile:

I 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.

Hello @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