In the following source code example / WordPress developer tutorial I will show you how to add a custom WordPress Widget area in your WordPress Theme. Adding a custom Widget area in WordPress requires just the addition of two pieces of PHP code in your WordPress Theme files.
First, in your WordPress Themes functions.php file add the following PHP code:
1 2 3 4 5 6 7 8 9 10 |
if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => 'Footer Widget', 'id' => 'footer-widget', 'description' => 'Widget Area', 'before_widget' => '<div id="one" class="two">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>' )); |
The above code will generate a Widget area for you to use in your WordPress Admin Dashboard. Now, the following PHP code needs to be placed in one of your Theme files in order for the contents of the Widget area to display on your WordPress site when viewed in a browser:
1 2 |
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer Widget') ) : ?> <?php endif; ?> |