• Hi,
    I’m having some troubles creating a child theme based on Twenty Twenty theme.
    After creating twentytwenty-child folder in “theme”, setting up function.php and style.css in it and setting the child theme on the backend, I can’t get it working.

    These are my style.css and function.php in my “twentytwenty-child” folder:

    style.css

    /*
     Theme Name:   Twenty Twenty Child
     Theme URI:    https://example.com/twenty-fifteen-child/
     Description:  Twenty Twenty Child Theme
     Author:       lup0z
     Author URI:   https://example.com
     Template:     twentytwenty
     Version:      1.0.0
     License:      GNU General Public License v2 or later
     License URI:  https://www.gnu.org/licenses/gpl-2.0.html
     Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
     Text Domain:  twentytwentychild
    */
    

    function.php

    <?php
    
    	add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    	function my_theme_enqueue_styles() {
    	    $parenthandle = 'twentytwenty-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    	    $theme = wp_get_theme();
    	    wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', 
    	        array(),  // if the parent theme code has a dependency, copy it to here
    	        $theme->parent()->get('Version')
    	    );
    	    wp_enqueue_style( 'twentytwentychild-style', get_stylesheet_uri(),
    	        array( $parenthandle ),
    	        $theme->get('Version') // this only works if you have Version in the style header
    	    );
    	}
    	
    ?>

    I’ve spent a lot of time searching for a solution in various websites, but I can’t make it work.

    Thank you for your reply

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,
    the following for your functions.php file should work (this is how I have it)

    function my_theme_enqueue_styles() {
     
        $parent_style = 'twentytwenty-style'; // Make sure here it's the parent theme.
     
        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' );

    You’ll find at WordPress Codex everything you need about Child Themes. Check it out at https://developer.www.ads-software.com/themes/advanced-topics/child-themes/

    Dear Laly,
    Just wanted to say a massive thank you for this code.
    I have spent a few hours using code for wp_enqueue_style function from two different sources and neither worked.
    Your code sorted me out and now my site works with child theme activated.
    Thank you again :)))

    Awesome!
    Thank you for taking the time to say thanks
    I’ll see if I can close this topic, ok?
    (If I can’t, please do so, so it’s marked as solved ??)
    Happy blogging!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Twenty Twenty child theme doesn’t work’ is closed to new replies.