WP plugin: My Widget – example WordPress widget
There’s a funky new WordPress plugin, WordPress Widgets, driving a fair percentage of the WP community to both ends of the enthusiasm spectrum. But love it or hate it, it’s here to stay, and you can pretty much expect to see it end up in the WordPress core in a not to distant future version.
With the appetizer out of the way, let me get to the meat of the post: a thread on the WordPress support forums lead me to the decision the example dev material provided is a bit weak, especially for the neophyte plugin writer. So in the interest of avoiding dozens of similar yelps for guidance over the months to come, I tore through the widgets that tag along with WordPress Widgets (the Google and del.icio.us ones) and after an hour had merged, molded and abused them into an example widget (with lots of explanatory comments!). And now I’m passing that work along to anyone who wants it.
The widget can be considered useful, to boot.
To install, download my-widget.php from here, upload that to your wp-content/plugins/ directory, and activate My Widget under plugins. It’s one of those you should already know this bits of wisdom, but you also need to have WordPress Widgets installed and activated as well, otherwise My Widget is little more than a piece of chocolate cake served up to a coma victim.
If you just want to use the My Widget widget, here’s what it does: when you add it on your sidebar by default it displays “My Widget” for the header (or title) and “Hello World!” for the text. Thankfully these can be edited through the widget’s control.
The little red arrow in the image above points at the control button on the widget bar. Click it and the following pops up:
Just add your own personal title and text, then close the My Widget dialog box and click Save Changes to, well, save the changes. Feel free to use it to display a welcome message or a note about yourself. I’m sure you can think of something to do with it.
So you see you can put it to use, but it’s main purpose is to provide a learning tool or framework for building your own widget. For that reason I’ve sprinkled comments liberally throughout the source code. However if anything is not clear, or if you have suggestions for making My Widget more useful, let me know.