WordPress – Widgets and CSS styling

Sep 6, 2007Blog, Web design, WordPress

Widgets (entry valid for WordPress v2.2.2) – In this version are already integrated Widgets for the sidebar, we will look more closely at how to use them and we will describe how to correctly styles using CSS. The theme directory you have a file functions.php to open it, right from the start is the definition of what will happen before and after the widget, the widget title.

if ( function_exists('register_sidebar') ) register_sidebar(array('before_widget' => '<li id="%1$s" class="widget %2$s">','after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',

1) If you are ok with the fact that all elements of the sidebar will be styling a single definition, adjust the following settings and enter the definition of the class .bar to file style.css.

.bar {	padding: 5px 5px 5px 5px;
	background: url('images/bar.jpg') no-repeat;
	color: White;
  }
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="bar">',
'after_widget' => '</div>', 'before_title' => '<h2>',
'after_title' => '</h2>',
));

Now check out folder /wp-includes/ and open file widgets.php and put above changes here too:

$defaults = array(
'name' => sprintf(__('Sidebar %d'), $i ),
'id' => "sidebar-$i",
'before_widget' => '<div class="bar">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
);

2) If you need some elements sidebar stylish different definitions, we have to reflect how these settings in the file widgets.php as individual files of the widget plugins. The following is an example of the various functions of the file widgets.php directly modify, add CSS class .bar

function wp_widget_meta($args) {
	extract($args);
	$options = get_option('widget_meta');
	$title = empty($options['title']) ? __('Meta') : $options['title'];
?>
<?php echo $before_widget; ?>
<div class="bar"><?php echo $before_title . $title . $after_title; ?>
<ul><?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo attribute_escape(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo attribute_escape(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="http://wordpress.org/" title="<?php echo attribute_escape(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
<?php wp_meta(); ?>
</ul>
</div>
<?php echo $after_widget; ?>
<?php
}>

Similarly we do with external widgets, the only way we will be able, for example, Event Calendar to use a different class.

  /** Event Calendar widget. */
  function ec3_widget_cal($args)
  { extract($args);
    $options = get_option('ec3_widget_cal');
    echo '<div class="otherbar">';
    echo $before_widget . $before_title;
    echo ec3_default_string($options['title'],'Kalendář');
    echo $after_title;
    ec3_get_calendar();
    echo '</div>';
    echo $after_widget;
  }

David

Graphic and website designer, currently maintaining web servers for existing clients and building websites for new clients. In my free time, I learn about Linux, SSH, and WP-CLI and I’m preparing this blog.

Related Posts

25+ Free Fonts for Your Next Design Project

25+ Free Fonts for Your Next Design Project

Looking for some fresh and creative fonts to spice up your design projects in 2023? You’re in luck! In this blog post, we’ve curated a list of 25 free fonts that you can download and use right away. These fonts are suitable for various purposes such as logos,...

Adobe Photoshop Shortcuts – Infographic

Adobe Photoshop Shortcuts – Infographic

Thanks to Amanda from the Consumer Base that she sent us an ultimate Adobe Photoshop shortcuts cheat sheet. If you are a beginner or want to brush up your knowledge on Adobe Photoshop shortcuts then you are at the right place. Have look at it and let us your thoughts...

20 WordPress Tutorial channels on Youtube

20 WordPress Tutorial channels on Youtube

This post will introduce you a useful list of the 20+ best currently active WordPress tutorial related channels on Youtube. These channels are mostly focused on Tutorials and Guides for Developers and Designers that want to learn all about WordPress. Check them out...

12 AI Tools for Graphic and Website Designers

12 AI Tools for Graphic and Website Designers

Artificial intelligence (AI) is transforming the way designers work, from ideation to execution. AI tools can help designers automate tedious tasks, generate new content, and enhance their creativity. In this blog post, I will introduce AI tools that you can use to...

How to Pair Fonts – Tips and Tools for Perfect Font Combinations

How to Pair Fonts – Tips and Tools for Perfect Font Combinations

Font pairing is the art of choosing two or more fonts that work well together and create a harmonious design. Font pairing can make or break your website, logo, poster, or any other project that involves typography. But how do you pair fonts like a pro? In this...

The Ultimate Guide to Color Palettes

The Ultimate Guide to Color Palettes

Color palettes are collections of colors that work well together and create a harmonious visual effect. They are essential for any design and art project, as they help to convey the mood, message, and style of your work. But how do you choose the right color palette...

Show/Hide Comments (0 comments)
L

0 Comments

Social followers

Articles

Visits

Pin It on Pinterest

Shares