Register Sidebars in Child Themes

When creating a child theme for MixWP framework you have the possibility to register custom widget areas (or generically called sidebars) beside the ones already existing in the parent theme. These sidebars are usually used for custom homepages.

Unlike the regular way of registering sidebars in WordPress themes we made this process a lot more easier for MixWP child themes trough a hook.

The function you are going to use is:

register_mixwp_sidebar();

and this will be added to your functions.php file.

The function will need to be placed as follows:

add_action ('mixwp_child_theme_sidebars', 'my_sidebars');
function my_sidebars () {
    register_mixwp_sidebar('name=Sidebar name');
}

Parameters

You are able to pass parameters for each sidebar as follows:
name - mandatory - you need to add a name to your sidebar
title_wrap - conditional (default h3) - heading tag that wrap the tile.
widget_wrap - conditional (default div) - wrap around the widget
description - conditional (default none) - a description of your sidebar

Example

using default parameters:

add_action ('mixwp_child_theme_sidebars', 'my_sidebars');
function my_sidebars () {
    register_mixwp_sidebar('name=My Sidebar');
}

using custom parameters (widget wrapped in li tag and title in h2):

add_action ('mixwp_child_theme_sidebars', 'my_sidebars');
function my_sidebars () {
    register_mixwp_sidebar('name=My Sidebar&title_wrap=h2&widget_wrap=li');
}

The sidebar ID will be generated automatically as lowercase title and "-" sign for spaces. So the sidebar ID from our example will be my-sidebar.

The widget class will be generated automatically as well as lowercase title and "-" sign for spaces plus adding -widgets at the end of the widget class. The widget class from our example will be my-sidebar-widgets.

Registering multiple sidebars is also possible by placing the function for every sidebar you want to register in your child theme functions.php file as follows:

add_action ('mixwp_child_theme_sidebars', 'my_sidebars');
function my_sidebars () {
    register_mixwp_sidebar('name=Homepage Top&title_wrap=h2');
    register_mixwp_sidebar('name=Homepage Bottom');
}

In this example Homepage Top widget title will be wrapped in H2 tag and Homepage Bottom widget title will be wrapped in the default H3 tag. Both widgets will be wrapped in a DIV.

Example usage in the child theme home.php file:

<?php get_header(); ?>

<div id="homepage">

<div class="grid_12">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('HomePage Top') ); ?>
</div>

<div class="grid_12">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('HomePage Bottom') ); ?>
</div>

</div><!-- end homepage -->

<?php get_footer(); ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>