WordPress Development: Replacing Default Widgets

Posted April 10th, 2008

I’ve been working on a little WordPress project these last few weeks with a colleague. When I first heard the idea, I thought, “That should be easy enough to build.” I decided the best way to tackle the feature would be a custom widget, but when I finally sat down to get it working I quickly began to realize that there were a few obstacles to overcome.

The project was really meant to extend an existing widget, and it seemed confusing to have both the default and extended version there side by side (plus it would be really nice to call them the same thing for transparency). I needed to get rid of it. You can’t just overwrite an existing widget by registering a new one by the same name - WordPress ignores it. And if I did manage to find a way to remove a default widget, when do you have to do it?

Luckily, some digging around found a solution.

1
2
3
4
5
6
7
8
9
10
function gdm_widget_meta_register() {
	// unregister the widget and its control
	wp_unregister_sidebar_widget('meta');
 
	// register the new and improved widget and control
	wp_register_sidebar_widget('meta', __('Meta'), 'gdm_widget_meta');
	wp_register_widget_control('meta', __('Meta'), 'gdm_widget_meta_control');
}
 
add_action('widgets_init', 'gdm_widget_meta_register', 1);

The really important pieces are the wp_unregister_sidebar_widget function and the widgets_init action hook. widgets_init actions are run right after all the default widgets are registered, giving us the perfect opportunity to call wp_unregister_sidebar_widget with the ID of the widget you’re getting rid of. Now you can register your own widget and control, effectively replacing a default WordPress widget.

15 Comments »


I’m not dead…really.

Posted December 9th, 2007

It’s been almost six months since my last post, and I just want to give everyone a heads up that I will be back very soon. The last six months have been quite exciting — graduation, a great new job, and a new apartment in Orchard Park, New York. Things have finally started settling down and I plan to get back to blogging in the next week or so. Wordpress’ Page Link Manager has a lot of new features coming which I think will be great additions, and I’ve been working on learning a bit of Ruby on Rails and jQuery, so I’m looking forward to sharing some of what I’ve learned with you.

In the meantime, check out my sisters new blog, rdmey. She posts great stuff nearly everyday about design, CSS and JavaScript, so it’s probably right up your alley.

4 Comments »


WordPress Plugin: Home Page Link

Posted July 31st, 2007

I received an email this evening from Dan, who uses the Page Link Manager, wondering how to get a home page link to show up in his site navigation. I had never really thought about the problem, or even realized it was a problem until I started my search for a solution. There’s not much out there covering the issue besides a few forum posts at WordPress.org. But it’s an issue, nevertheless. I understand that the blog’s heading is supposed to link to your home page, but I believe there’s a large audience of Internet users, and potential readers, that wouldn’t think to look to a heading for a shortcut back to your home page.

And so we have the Home Page Link plugin.

The Plugin

v0.15 Release Changes (August 12, 2007)

This is a bug release.

Better Compatibility
The plugin now works whether your using the Pages widget or wp_list_pages.

The plugin does just what you think - adds a Home link to your site navigation (wp_list_pages). And it’s very easy to use.

  1. Download and unzip the plugin archive.
  2. Place the plugin file under wp-content/plugins directory on your Wordpress Installation
  3. Log in to your admin interface and activate Home Page Link under the ‘Plugins’ tab

That’s it! You should now be able to view your site with its shiny new Home link.

Like my other plugins, I hope to keep this going as a work in progress, and work along with the WordPress community to make it more useful and efficient. If you have something you’d like to see in an upcoming version, please don’t hesitate to add a comment or contact me.

Requirements

The current release requires a server running at least PHP4. The plugin has been tested on Wordpress 2.x. If anyone has gotten it working on older versions of Wordpress, please let me know.

Resources

If you’re interested in writing plugins, the Wordpress Plugin article is an excellent resource.

Download the Plugin

All source code is provided under the Creative Commons Attribution-Sharealike License. If you agree to these terms, please download the plugin now.

75 Comments »


Page Link Manager Now Available at WordPress.org

Posted June 16th, 2007

With the recent release of Page Link Manager v0.3, it has been added to WordPress.org.

I’ll still be hosting and supporting the plugin here for any of you that like to go straight to the source, but I’m hoping it will be easier to find and discover by other WordPress users over on the plugin site.

11 Comments »