WordPress.org

Ready to get started?Download WordPress

Forums

Remove Whitespace from empty titles of widgets on sidebar (4 posts)

  1. theresalwaysaway
    Member
    Posted 2 years ago #

    I added a second widgetized sidebar to a theme and I am trying to figure out how to remove the whitespace from a widget that doesn't have a title. In the functions php I added this code:

    register_sidebar(
        array(
          'id' => 'left',
          'name' => __( 'left' ),
          'description' => __( 'Left Sidebar' ),
          'before_widget' => '<div id="%1$s" class="widget %2$s">',
          'after_widget' => '</div>',
          'before_title' => '<h3>',
          'after_title' => '</h3>'
        )
      );

    and I because of the h3 tags it appears to be just trying to keep the space open for a title regardless of if there is one on the widget. If I place the title onto the widget it shows up and fills the whitespace. For this theme, I would like to have some sort of if statement in place that detects the presence of a title before proceeding to reserve that space so that the theme comes out clean.

    Does anyone have a clue on how to implement that? I have no idea where to start or what syntax would be needed.

    Thanks in advance.

  2. theresalwaysaway
    Member
    Posted 2 years ago #

    I am pretty sure I could put an if statement before this:

    'before_title' => '<h3>',
          'after_title' => '</h3>'

    My question is, is there something like this?

    if (widgetHasTitle)
    {
    'before_title' => '<h3>',
          'after_title' => '</h3>' }
    else
     {'before_title' => '',
          'after_title' => ''}

    The API must have a solution right?

  3. diragusa
    Member
    Posted 2 years ago #

    was a solution ever found?

  4. theresalwaysaway
    Member
    Posted 2 years ago #

    No, I haven't found a solution. The best thing I can suggest is putting some information into the title of the widget at all times.

Topic Closed

This topic has been closed to new replies.

About this Topic