Issues with Customizer using Child Theme


#1

Hello,

I’ve created a child theme of Hiero on an newly installed, clean Wordpress without any plugins. I created the child theme directory, added a style.css with the appropriate header, and a functions.php in which I enqueued style.css with the following code:

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 99 );

	function theme_enqueue_styles() {
		wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

When I go for Appearance >> Customize, changes in the color and font-settings didn’t preview instantly and also can’t be saved. Furthermore, equivalent changes in the (child-)style.css only apply with the !important-hack.

When the $priority-setting in the mentioned code is 10 or below, changes in the customizer apply, but mash up a whole lot of other css. This also happend when using @import (what I do not want).

If the $priority-setting is 11 or above: no changes apply.

What am I doing wrong? Thanks for your help!

(sorry, can’t post link to site, because the project is in a loc dev environment.)


#2

Hi Skarkiel, i think this topic will be helpfull for you


#3

Great, thanks a lot! Now it works.

Code for solving the problem:

function use_parent_theme_stylesheet() {
    // Use the parent theme's stylesheet
    return get_template_directory_uri() . '/style.css';
}

function my_theme_styles() {
    $themeVersion = wp_get_theme()->get('Version');

    // Enqueue our style.css with our own version
    wp_enqueue_style('child-theme-style', get_stylesheet_directory_uri() . '/style.css',
        array(), $themeVersion);
}

// Filter get_stylesheet_uri() to return the parent theme's stylesheet 
add_filter('stylesheet_uri', 'use_parent_theme_stylesheet');

// Enqueue this theme's scripts and styles (after parent theme)
add_action('wp_enqueue_scripts', 'my_theme_styles', 20);

#4

Happy to see you solve problem, feel free to ask more questions

Thanks!