Widget Trouble

I had some trouble finding examples on how to Widgetize your WordPress Theme. I found plenty of links but all were dead. I figured I’d mirror a how-to guide here to make it easier for people to find out how to make their Theme work with WordPress widgets.

First of all you’ll want to put some code in your sidebar.php file to have a default sidebar as well as a dynamic sidebar when available. to do this use something like the following:

<ul id="sidebar">
    <?php if ( !function_exists('dynamic_sidebar')|| !dynamic_sidebar() ) : ?>
    <li id="about">
        <h2>About</h2>
        <p>This is my blog.</p>
    </li>
    <li id="links">
        <h2>Links</h2>
        <ul>
            <li><a href="http://example.com">Example</a></li>
        </ul>
    </li>
    <?php endif; ?>
</ul>

This will enable your site to use a dynamically generated sidebar. Next we need the ability to implement a dynamic sidebar. To do this simply add the following to your functions.php file:

<?php
if ( function_exists('register_sidebar') )
    register_sidebar();
?>

Provided you have the Widgets plug-in installed and activated, you should now see a ‘Sidebar Widgets’ section under Presentation in the Admin section of your site.

I am not the original author of this tutorial nor am I a contributor in any way to the Widgets plug-in. If you have questions about the plug-in itself, or this method is not working please contact the author or see the plugin website.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s