Want to add a Widget to your WordPress Blog?

by Ed Gately on March 11, 2010 · 6 comments

in Wordpress Advanced,Wordpress General Tips,Wordpress Theme Tips

One of my favorite features of WordPress is the fact that it is so very customizable.  And it’s so very easy to add in pieces that maintains a level of control over the site without having to manually change PHP or HTML files.  You can access it all from within the back end of WordPress.

You can customize these pieces and this extra control with Widgets.  I’m not going to go into to much detail here.  If you’ve been using WordPress for very long you know what Widgets are.

The key point here is that you can add a Widget section and then easily control, add, edit the content of that section from the admin of WordPress under the Appearance section.

Adding a Widget section is pretty straight forward even.  In your functions.php file, (or custom_functions.php for Thesis) you will just need to add something similar to the following line:

register_sidebar(array('name'=>'New Widget', 'before_title'=>'<h3>', 'after_title'=>'</h3>'));

The above is pretty simple right?  The “name” is set to whatever you want to call it.  And then you set the tags you want to wrap around the title. Make sure you use something descriptive for the name so you know what the widget is for.

After adding this to the function file you should be able to visit the Widgets section under Appearance and start adding Widgets to it immediately.

But we still have to decide where the widget is going to show up.

So in your template page you’ll need to add some code to set where the Widget shows up.  Usually you’ll add some default text that will display if there are no Widgets for that section yet.  Here’s an example, naturally you can style it how you want:

<div id="footer-widgeted">
<div>
<ul id="footer-widget">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('New Widget') ) : ?>
<li>
<h3>Testing Widget Area</h3>
<p>This is an example of a widgeted area.</p>
</li>
<?php endif; ?>
</ul>
</div>
</div>

That should do it. In a future post I’ll go into more detail and give some specific examples of adding widgets around a site.

Related posts:

  1. Accessing WordPress functions from external PHP pages
  2. The Hottest WordPress Theme on the Market just got Hotter
  3. WordPress 2.7 Permalink Issue and Fix
About The Author: Hi, I'm Ed Gately and I write Wordpress Master to help bloggers get started in building a successful online blog using Wordpress. Prior to writing on this blog I spent over 16 years working in Corporate IT and have been spreading my wings on the web for 3 years. To learn more about this website and me visit About Wordpress Master.

{ 6 comments… read them below or add one }

offtomobil123 February 17, 2012 at 3:49 am

Автомобильный блог, автоновости, авто тюнинг, новые автомобили, спорткары, концепт

Reply

Thomas May 21, 2012 at 11:19 am

SiteSubscribe: That sounds like a WP-bug of some sort. Shouldn’t be bcseuae of the plugin I don’t think.Harry: At the moment this plugin only works with the custom post type. Not sure why the social media/share buttons shows though. Which plugin is it and I could have a look at it?Anna: Try the beta 3 of version 1.0.0. That version has a search function. But it sounds like a bug that only 10 latests posts shows. So I will fix that and I think it’s time for a 1.0.0 version after that. 0

Reply

debfkabpbf May 22, 2012 at 6:41 am

H9VoLA , [url=http://zbrecdorvmda.com/]zbrecdorvmda[/url], [link=http://wwxmucjlltnh.com/]wwxmucjlltnh[/link], http://ztxrskojswzk.com/

Reply

transflorida February 21, 2012 at 8:45 am

Financial News Advices

Reply

Deepak May 22, 2012 at 1:04 pm

Добрый день.По вашему рецепту я ждал целый день ни хера.В итоге, добавил в файл header.php непосредственно после через 10 минут все заработало. WP 3.1.1

Reply

richarddienwinfield February 27, 2012 at 7:41 am

The Insurance Blogger is an expert independent blog providing news and comment on all aspects of the USA insurance industry.

Reply

Leave a Comment

Previous post:

Next post: