Support » Theme: Twenty Twenty » Twenty Twenty child theme doesn’t work

  • 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:    http://example.com/twenty-fifteen-child/
     Description:  Twenty Twenty Child Theme
     Author:       lup0z
     Author URI:   http://example.com
     Template:     twentytwenty
     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:  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 1 replies (of 1 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.wordpress.org/themes/advanced-topics/child-themes/

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.