Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Why are my widgets not showing up in the child theme I created?

I used the theme created in this tutorial as the parent theme. I am using the following code to enqueue my parent and child themes:

<?php 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);

?>

Thanks for any suggestions.

3 Answers

Sorry to trouble you - I managed to solve it. I used this code instead from Wordpress codex (https://codex.wordpress.org/Child_Themes):

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { 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') ); }

Actually I thought I had solved the problem but it turned out I actually had the parent theme activated. With the child theme activated same problem I am afraid.

It turns out the widgets have moved to the "Inactive widgets" area so I can drag them back to activate them again. I still don't understand though whether this is normal behaviour whenever you create a child theme. I would have thought the child them would have inherited the widget functionality defined in the parent theme rather than having to repeat the process of setting them up for the child theme? Maybe I am missing something.