'id', 'class' and 'show heading' attributes for widgets
I often don't want to display widget headings, so I set them to ' ' (blank), but that still puts the H3 tag into the code and sometimes interferes with styling.
To allow further styling, I often create a text widget with its content wrapped inside a container with an 'id' or a 'class', which I then style. Very often, I include the H3 tag there too.
I suggest that widgets allow the assignment of the 'id' and 'class' attributes for styling purposes, as well as a tickbox for not showing the heading at all.
If you are a theme developer you can assign this dynamically using something like the following code:
$args = array(
'name' => 'Blog Sidebar',
'id' => 'blog-widget-area',
'description' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
register_sidebar( $args );
You can then target specific widgets using css. Does that make sense?
That doesn't actually address my needs and certainly doesn't cater for people who aren't theme developers.
Within the same sidebar, I want to be able to turn off headings for some widgets, but not all. I also want to style some widgets a certain way and some in another way in the same sidebar. And I want to be able to do all this from within the widget admin page, which I think is very possible.
Using widget IDs as per your code gets messed up as soon as I make changes to the widgets, because WordPress may reassign their numbers. Even if not, it requires making CSS changes for every single widget, which is a lot more work than necessary.
Empty heading/title is the widget's author responsibility. A good widget should never output the title when it's set to blank by the user.
As for the ID and classes, you may want to try my plugin
RSS feed for this topic
You must log in to post.