Tutorial 3: How to create a WordPress Sidebar Widget using Plugin ?

by Aky Joe on January 16, 2010

Thesis Theme

WordPress widgets are the dynamic objects which eases the customization of the content on sidebars and widgetized footers. Widgets allows drag-n-drop interface in the Dashboard admin panel, for easy management.

These widgets are usually registered either at the time of Theme activation or any activation of Plugin. Well in the tutorial, I’ll explain you how to create a wordpress widget and the basic registration of a Widget using my-first plugin, which we developed in our earlier tutorial. My links to earlier tutorials are:

Well, in our exiting PHP code, in my-first.php we will code in order to register a widget, when a plugin is activated. Below is the code:

Code: To register a Widget in Sidebar

   1: /* This Registers a Sidebar Widget.*/

   2: function widget_myfirst() {

   3: ?>

   4:   <h2>My First Widget</h2>

   5:   <?php my_first(); ?>

   6: <?php

   7: }

   8:

   9: function myfirst_install()

  10: {

  11:   register_sidebar_widget(__('My First Widget Plugin'), 'widget_myfirst');

  12: }

  13: add_action("plugins_loaded", "myfirst_install");

Once the above code is appended in the my-first.php file, activate the plugin. And navigate to Dashboard > Appearances > Widgets. On the right side interface, the widget My First Widget Plugin is listed, which can be further draged in to the

image

Once the plugin is listed under WordPress Widgets, drag-drop the widget to the appropriate Sidebar or the any other widgetized footer.

image

Once the widget is placed on the sidebar, refresh the site, in order to list the plugin on the sidebar.

image

Well, the above screenshot meets us our requirement, and ends this tutorial. Its been nice week of development, I’ll come up with more of the innovations, soon with How to Create WordPress Plugin.

For any queries or further assistance required, kindly post comments as your feedbacks.

Related posts:

  1. Tutorial: How to Create WordPress Plugins
  2. Tutorial 2: How to Create WordPress Plugin Admin Panel
  3. How To Make Tabbed Widgets In WordPress With The Section Widget
  4. Rotating Ads On Sidebar Header Widgetized WordPress plugin : Adrotate
  5. Drag to Share WordPress Plugin Extended : Share Image With one Click

Wpfreelancer

Leave a Comment

Previous post:

Next post:

.