Add Widget Area Location

If you’re looking to just create your own standard widgetized area, you can do that by using register_sidebar() and displaying it on the frontend of your website with dynamic_sidebar(). This is a standard WordPress process that’ll work, no matter what theme you’re using.

But in embracing our framework, there’s also another way. In this article, we’ll discuss an alternative to the default WordPress process of setting up a sidebar, that’ll allow the end user to manage custom widget areas via our widget areas plugin.

Widget Areas “Locations”

If you’re using our widget areas plugin, there’s a fancier way you can set all this up. Instead of creating just a standard widgetized area, you can create what we call a widget area location. A location allows the end-user to create custom widget areas and assign those widget areas to the custom location, for specific pages of their website.

To do this, you’ll use themeblvd_add_sidebar_location() to register the widget area location, and then you’ll use themeblvd_display_sidebar() to display it on the frontend of your website.

By default, this will work similarly to the default WordPress process. When you add your location, a default widget area will appear for the user at Appearance > Widgets, and it’ll display any widgets added to it, across your entire website. However, because you used our method of adding it as a location, now the user can swap in custom widget areas, created at Appearance > Widget Areas, on assigned pages of their website.

Adding a Widget Area Location

To create your custom widget area location, you’ll use the the function themeblvd_add_sidebar_location().

themeblvd_add_sidebar_location($id, $name, $type, $desc);
(string) (required) ID of new widget area location.
Default: None
(string) (required) Name for new widget area location.
Default: None
(string) (required) Type of widget area location - fixed or collapsible. See here for more information on location types.
Default: None
(string) (optional) Description for the widget area location.
Default: This is default placeholder for the {$name} location.
themeblvd_add_sidebar_location('my_location', 'My Location', 'collapsible');

Displaying a Widget Area Location

Next, to display that widget area location you created, you’ll use the function themeblvd_display_sidebar().

(string) (required) ID of widget area location you set up with themeblvd_add_sidebar_location().
Default: None

Full Example

Now, we’ll put this all together in a logical example. Let’s say we want to add a custom widget area location to the header of our website. We’ll first add the widget area location, and then we’ll display it in a custom function we hook to themeblvd_header_addon (see actions map).

So here’s how you’d implement this example from your child theme’s functions.php.

 * Register widget area location.
themeblvd_add_sidebar_location('my_header_location', 'Header Widgets', 'collapsible');

 * Display widget area location.
function my_header_widgets() {
	<div class="header-widgets">
	   <?php themeblvd_display_sidebar('my_header_location'); ?>
	</div><!-- .header-widgets (end) -->
add_action('themeblvd_header_addon', 'my_header_widgets');

And after a long article, aside from maybe some CSS styling, that’s really all there is to it!