Top

How to Add Additional Widgets to a TwentyTen Child Theme

March 25, 2011

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:

register_sidebar( array(
    'name' => __( 'Your Widget Area', 'your_child_theme' ),
    'id' => 'my-widget-area',
    'description' => __( 'The primary widget area', 'your_child_theme' ),
    'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

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:

<?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.

Tweet This Post

This theme is provided free of charge, provided you leave the "Wordpress Theme From Pressography.com" attribution link at the bottom of the theme.

If you want to remove the attribution link, you must pay a small, $10 license fee for each site on which you want to remove the link. Click Here For More Information

Comments

Got something to say?

Bottom
Article Archive  |  This site is a historical archive of pressography.com, a WordPress plugin and theme blog that published between 2006 and 2012. It is preserved for reference and is not operated by, affiliated with, or endorsed by its original authors. Nothing here is for sale and no form on this site is active. If you are the original owner and would like this domain returned, please get in touch.