From the course: WordPress: Building Child Themes

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Conditional widgetized area

Solution: Conditional widgetized area - WordPress Tutorial

From the course: WordPress: Building Child Themes

Start my 1-month free trial

Solution: Conditional widgetized area

(upbeat music) - [Instructor] I hope you gave this challenge a try, because conditionally hiding content is pretty common in child themes. If we scroll down, you can see that I have my widget area here. And if I go to a single post, you can see there's no widget area. So let me go to the functions.php file, and I'll show you how I did it. The first thing we had to do, is we had to disable the line that we added in our original functions file. So that's remove action widgets init. So I disable this. Then I opened up footer-widgets in my parent theme and I copied it to my child theme. There's a line right here, is_active_sidebar, and it was originally like this, is_active_sidebar, and I added these two conditionals: If there's an active sidebar, and it's not a single post, and it's not a page, then print all of this information. That is all that you had to do. One line, and it works. We can, however, optimize this code just a little bit more. There is a similar function called…

Contents