How to widgetize a theme with dirty code

Discussion in 'WordPress' started by geegel, Sep 15, 2008.

  1. #1
    I happen to have a brand new wordpress blog, for which I have found the perfect theme and a few widgets I would've loved to have.

    The problem was that this specific theme has some very dirty code so the traditional way of widgetizing did not really work. After several hours of frustrations, I smacked myself on the forehead and this is what I did:

    in the functions.php I added:

    
    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    
    Code (markup):
    This is the standard I know.

    After that I went to sidebar.php and (the breakthrough came here) instead of trying to widgetize it all, I settled for the area between "Categories" and "Monthly archives" so I inserted the following code:

    
    <ul>
    
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    <?php endif; ?>
    
    </ul>
    
    Code (markup):
    And voila now I have a blog with widgets

    I really hope that this will help other bloggers avoid my headaches.

    Happy blogging.

    Regards, George
     
    geegel, Sep 15, 2008 IP
    Matt B likes this.