For a yoga school with different centers in various cities I needed a variable sidebar, so each city has its own sidebar displayed on all their specific pages and posts. There are good plugins to achieve this, but I keep the number of plugins as little as possible. So whenever I can solve something in the child theme files, I prefer that version, and since DIVI offers the creation of sidebar areas, the automatic assignment to different users – one for each city – was a question of just a few lines of code. If you use the created sidebars together with the sidebar module of the DIVI Builder, you don’t need any code, you just select them there. But I am using sidebars also on regular pages and posts and I like them to go all the height, read this article to see what I mean and how I achieve this in my child theme.

To create additional sidebars in DIVI, go to Appearance / Widgets and find the box on the right side. Take the note of “Naming your widget area “sidebar 1”, “sidebar 2”, “sidebar 3”, “sidebar 4” or “sidebar 5” will cause conflicts with this theme” serious, choose an appropriate name and click the Create button. Now your sidebar is ready to be equipped with the widgets of your choice. Now, to display the sidebar according to the author of the page or post, we just need to add a few lines to the sidebar.php (of course in best case into its copy in our child theme to not loose the changes during next update). Replace the line

with

Leave the else condition untouched, but replace “berlin” and “freiburg” and the author ID’s with your own. If you need more, copy another elseif section. If you need less, delete the elseif section. That’s it, no need to bloat up your website with another plugin.