WordPress 2.8 Widget API

Sunday, 14th June 2009

I love the new widgets API in WordPress 2.8

I followed the excellent tutorial at WPengineer.com which gives a great overview about how to create a widget using the new API. Initially, the widget I created by following the guide seemed to ‘crash’ WordPress when I installed it. After a little investigation I tracked this down to the following…

1
2
3
4
function widget_myuniquewidget_register() {
   register_sidebar_widget('My Unique Widget','widget_myuniquewidget');
}
<strong>add_action('init', widget_myuniquewidget_register);</strong>

You must initialise the register_sidebar_widget function by hooking into the ‘init’ action. Failure to do so means the function is called too early which will cause problems. For more information read WordPress Widgets API on the WordPress Codex.

Share:
  • email
  • Twitter
  • Digg
  • Slashdot
  • Google Bookmarks
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Ping.fm
  • Facebook
  • Technorati

Leave a Reply