• Hi Ben …

    I’m baaaaaack! =:o

    What a long strange trip this has been. The WordPress uber-tech at A2 Hosting figured out the issue & fixed it & then some! Figured you’d want to know & possibly update your child themes too … or not. ??

    The short version: He removed the @import in the child stylesheet and created an enqueue function in the child theme functions.php file. This is also how the WordPress Codec is asking developers to set up child themes too; using enqueue function, rather than @import.

    From the WordPress Codec:

    The final step is to enqueue the parent and child theme stylesheets. Note that the previous method was to import the parent theme stylesheet using @import: this is no longer best practice. The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme’s functions.php …

    .

    Here is the reply I got yesterday from A2:

    The cause was a constant in the wp-config.php file set to define the stylesheet path. It was causing the child theme to break. I’ve not seen this happen before so it took a bit of troubleshooting, including using two themes I knew would work together (as a parent and child). When those two wouldn’t work either, I knew something else was going on. After finding the cause, I went back into your child theme and changed two things. I rewrote the child theme header in the stylesheet and I added a function to the functions.php file to enqueue the parent and child theme. What the function does is add the parent stylesheet first, then follows up with the child stylesheet. Anything you write into the child stylesheet will come after the parent stylesheet has loaded, so you can override parent styles.

    I renamed your original stylesheet to style1.css. This prevents it from running on the theme, but also keeps it there so you can get to any styles you need to copy over. The style.css file I created is basically empty, other than the header to tell WordPress which template it needs to use. It also lists your site as being the author of the template. While that part isn’t necessary, I figured that if someone looks at your stylesheet , they’ll see that you were the author of the child theme. I thought it might add a little more credibility to you for the design changes since you’ll be modifying it yourself.

    I added comments to the function so you’ll be able to see why each line is present. Also, since the parent is being enqueued with WordPress, it’s not using the @import in the child stylesheet. This is better for the site, which can be best explained here by GTMetrix: https://gtmetrix.com/avoid-css-import.html

    Functions.php file code:

    <?php
    
    // Enqueue the CSS
    add_action( 'wp_enqueue_scripts', 'go2jo_enqueue' );
    
    function go2jo_enqueue() {
    
    	// Set the parent stylesheet name. In this case, the parent theme developer labeld it "ct-tracks-style"
    	$parent_style = 'ct-tracks-style';
    
    	// Enqueue the parent theme stylesheet
    	wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    
    	// Enqueue the child theme stylesheet, with the parent as a dependancy. This way the child will load after the parent. No need to import.
    	wp_enqueue_style( 'child-style',
    		get_stylesheet_directory_uri() . '/style.css',
    		array( $parent_style )
    	);
    }

    This is the style.css file in the child theme:

    /*
     Theme Name:   Tracks Child Theme
     Theme URI:    https://www.go2jo.com/
     Description:  This is a child theme used to customize the Tracks WordPress theme.
     Author URI:   https://www.competethemes.com
     Template:     tracks
     Version:      1.0.0
     License:      GNU General Public License v2 or later
     License URI:  https://www.gnu.org/licenses/gpl-2.0.html
     Text Domain:  tracks-child
    */
    
    /* =Theme customization starts here
    -------------------------------------------------------------- */

    Hope this helps you out.

    Thanks so much for all your help, Ben! Figured I’d pay it back a bit. And if you want to just make this post private … that’s fine too. Don’t want to confuse others, or make your support job harder.

    https://www.go2jo.com

Viewing 1 replies (of 1 total)
  • Theme Author Ben Sibley

    (@bensibley)

    Joe,

    That was really considerate, thanks so much for sharing! I had seen that WP updated their recommendation for child theme style importing, but didn’t think it would make much of a difference. I’ll be updating the starter child themes I provide to avoid any edge cases like this in the future.

    Thanks again!

Viewing 1 replies (of 1 total)
  • The topic ‘Child Theme Functions.php – Finally Fixed!’ is closed to new replies.