How to Add Additional Widgets to a TwentyTen Child Theme

How to Add Additional Widgets to a TwentyTen Child Theme

Adding more widget areas is a very handy WordPress skill to have in your toolbox. Perhaps you have found the perfect TwentyTen child theme but it it doesn’t have as many widget areas as you’d like. This tutorial will show you how to create your own custom widget areas and add them to your theme.

Technically this process is pretty much the same for any other WordPress theme. When working with a TwentyTen (or any other) child theme, you’ll want to make your additions to files within the child theme directory.

First, you must register another Widget area in your child theme’s functions.php file:

{code type=php}register_sidebar( array(
‘name’ => __( ‘Your Widget Area’, ‘your_child_theme’ ),
‘id’ => ‘my-widget-area’,
‘description’ => __( ‘The primary widget area’, ‘your_child_theme’ ),
‘before_widget’ => ‘

  • ‘,
    ‘after_widget’ => ‘

‘before_title’ => ‘

‘after_title’ => ‘

) );

Modify the code above in the following ways:

  • Replace the ‘Your Widget Area’ with a name for the area you are creating.
  • Replace ‘your_child_theme’ with the name of your child theme.
  • Give your widget area an ID to use within your theme.
  • Give your widget area a description to replace ‘The primary widget area’ and add the name of your child theme again.

Those are the only areas you should need to replace in the code above.

Now, here’s the bit you’ll need in order to place your newly registered widget area in your child theme:

{code type=php}<?php
if ( is_active_sidebar( ‘my-widget-area’ )) {
dynamic_sidebar( ‘my-widget-area’ );

Replace ‘my-widget-area’ with the widget ID you created in the first step. You can place this code anywhere you want within your child theme, ie. footer.php, page.php, header.php, etc. For example, if you want to add a widgetized area to the top of your posts where you can add advertisements or notices, then drop the widget placement code into your single.php file. Make sure this is a copy of the parent theme’s single.php file and that it resides in your child theme’s folder.

This code is good for one additional widgetized area. If you want more unique areas, simply duplicate this and register as many widget areas as you like, making sure to create a unique ID for each. Have fun and don’t worry about making mistakes, because you always have the parent theme files to revert back to if something goes wrong.

Related posts: