Support » Themes and Templates » Adding img & div tags in sidebar.php before each widget doesn't work

  • Hi there,

    I am setting up my first WordPress site and I have managed to screw something up.

    Basically I have set up a WordPress website on my server, and I am making it look like the main website. One of the ‘features’ on the site is that all the widgets have an image (paperclip) and a background colour (here’s a screenshot).

    This is achieved by using the following img and div tags:

    <img class="paperclip" src="link" alt="paperclip" />
    <div class="sidebar">
         <!-- widget code-->

    I managed to add this styling to the widgets in WordPress before by adding the img and div tags in front of every widget within sidebar.php of my theme (see below):

    <img class="paperclip" src="link" alt="paperclip" />
    <div class="sidebar">
         <li id="search" class="widget-container widget_search" style="list-style:none;">
              <?php get_search_form(); ?>

    My hard drive then stopped working and I had to re-install WordPress and stuff. The problem I’m having now is that I can’t seem to add the styling to the widgets like I did before.

    Before my hardware failed, I was using WordPress 3.3.1. Now I’m using the latest 3.4 version. I don’t think there’s a problem with the version of wordpress I’m using because I even tried installing the old version and making the same changes.

    Luckily I had the whole WordPress folder backed up on my system (just before hhd crashed), so I tried uploading the files, but the widgets still don’t appear like before.

    So what am I missing? Or what would you suggest I do to add the same styling to the widgets in wordpress?

    Your help is much appreciated. Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • do this with CSS instead having the paperclip image as a background: url( enclosing the wrapper of the widget.

    for example

    .widget-container {
          background: url(link) top center no-repeat;
          height: 300px;
          width: 200px;
          display: block;

    If that doesn’t work for you because of variable height of widgets, you can edit the function that registers the sidebars to add a <div class="widget-head"></div> to it, so that you then use that .widget-head instead.



    Forum Moderator

    are you hard-coding this into sidebar.php?

    or are you using this within the ‘register_sidebar()’ function in functions.php of your theme?

    are you using widgets from within ‘dashboard – appearance – widgets’?

    what is the result at the moment?

    can you post a link to your site to illustrate what you have now?

    @frumph: Thank you. I’ll give it a shot later and tell you how it’s going.

    @alchymyth: Yes. I hard-coded the code into sidebar.php. And the only widgets that I’m using at the moment are ‘Search’, ‘Archieves’ & ‘Meta’. And at the moment there is no styling. The main site is : and the blog is at (Please note that the server is down between 11pm and 8am UK time)



    Forum Moderator

    seems you are using widgets, in which case the hard-coded section might not get applied;

    please paste the full code of sidebar.php into a and post the link to it here – HOWTO.

    Thank you for your reply. Here’s the code used in sidebar.php that worked before I re-installed wordpress.

    I appreciate your help.



    Forum Moderator

    everything from line 18 to line 48 will not get used if you are using real widgets within dashboard – appearance – widgets – as you are doing now.

    goto dashboard – appearance – widgets and remove all widgets from the primary and secondary widget areas.

    guess – possibly before the update you were not using widgets, but relying on your hardcoded output.

    Ok I understand. So how would I be able to add the custom styling to ‘real widgets’?

    I’m a newbie and I’m just getting started with all this programming so please bear with me 🙂



    Forum Moderator

    have you tried to drag the widgets off the widget areas?
    and what was the result?

    add the custom styling to ‘real widgets’

    you need to edit the way the sidebars are registered in functions.php:

    codex chapter:

    i.e. the ‘before_widget’ and ‘after_widget’ arguments.


      'name' => __( '????keep what you have here????' ),
      'id' => '????keep your id????',
      'description' => __( '????keep your text????' ),
      'before_widget' => '<img class="paperclip" src="" alt="paperclip" />
                    <div class="sidebar">
                            <li id="%1$s" class="widget-container %2$s" style="list-style:none;">
      'after_widget' => '</li></div>'
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>'

    (btw: the use of ‘div’ in the code will generate invalid html code; although most browsers will display it somehow)
    possibly try to change ‘div’ to ‘ul’ in the above code.

    if you have problems, you can paste your register_sidebar() code into a pastebin and post the link to it here.

    I just tried removing all the widgets and yes it works like you said 🙂

    Thanks for the link. I’ll go over the stuff and make the appropriate changes. If there are any problems I’ll update the post.

    Thank you. Your help is much appreciated.

    Hi there,

    Thank you for your help. I have managed to get it to work.

    You were right about using the div tags. I tried adding the div tags in and IIS gave me a 500:Internal Server error.

    But to get around that I just removed the div tags and styled using the list (widget-container).

    Thank you once again. 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Adding img & div tags in sidebar.php before each widget doesn't work’ is closed to new replies.