1

I am trying to create a child theme, and have come up with this.

    <?php
// Exit if accessed directly
if ( !defined('ABSPATH')) exit;

// BEGIN ENQUEUE PARENT ACTION

if (!function_exists('chld_thm_cfg_parent_css')):
    function chld_thm_cfg_parent_css() {
        wp_enqueue_style('chld_thm_cfg_parent', get_template_directory_uri() . '/style.css'); 
        wp_enqueue_style('chld_thm_cfg_parent', get_template_directory_uri() . '/style.min.css'); 
    }
endif;
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css');

// END ENQUEUE PARENT ACTION

The purpose of this line wp_enqueue_style('chld_thm_cfg_parent', get_template_directory_uri() . '/style.min.css'); is to get the style.min.css from the parent theme. However, when I check my live preview, it does not have the same font size that I set in style.min.css in the parent theme. Also, copying style.min.css into the child theme's folder does not seem to be wrong.

What should I do instead?

3

You are using the same identifier for style.css and style.min.css. Use a different identifier for each one.

Better: assuming that style.min.css is the minified version of style.css, enqueue only style.min.css.

if (!function_exists('chld_thm_cfg_parent_css')) {
    function chld_thm_cfg_parent_css() {
        wp_enqueue_style('chld_thm_cfg_parent', get_template_directory_uri() . '/style.min.css'); 
    }
}
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css');

Finally, clean the browser cache after changing the content of the style.min.css file. Otherwise the browser can use a old version stored in local cache.

To ensure your user will get the correct file, it is recommend to use the version parameter of wp_enqueue_style and change the version number each time you modify the style file:

if (!function_exists('chld_thm_cfg_parent_css')) {
    function chld_thm_cfg_parent_css() {
        //Fill with dependencies, if any
        $dependencies = array();
        //Change the version number after you change the content of the file
        //To ensure that browsers download it again and discard the one stored on cache
        $version = '1.0':
        wp_enqueue_style('chld_thm_cfg_parent', get_template_directory_uri() . '/style.min.css', $dependencies, $version ); 
    }
}
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css');
  • 1
    Why did you approve such thing? It should be rejected, obviously. – cybmeta Jun 8 '17 at 5:33
  • 1
    I apologize the images didn't load for me due to slow connection. I thought they were part of the answer originally. That's why i immediately left a comment. – Jack Johansson Jun 8 '17 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.