Back to Top

How to Create a Custom WordPress Widget

Create Widget in Wordpress

Today I am going to share one my experience in WordPress. Recently I have developed widget for one of my plugin Direction Map.So I am going to explain how you can create own WordPress widget.

WordPress has a lot of very handy features and Widget is one of the same.Widget in WordPress is to add dynamic content and features to sidebars.so I must say widget is very good and useful feature of WordPress for technical and non-technical both users.

So, Let’s dive into the code

First of all, Create one file with the name of demo-widget into your plugin or you can add your code into functions.php file or you can place below code into your plugin main file if you want to create widget for your plugin.

Step 1:

Here, In above code, I have just initialised my widget using action hook and will write widget code into the included file widget.php.

Step 2:

Now, Let’s create file widget.php at the same place or you want to have it.

In this file, first of call the following function

and next, extend the WP_Widget core class with Demo_Widget class

Now,we will call constructor within class say,

Step 3:

To display the widget on the screen, we will call below function into the class

Step 4:

To update any the widget settings, you need to call below function into class

Step 5:

Last but not the least, to displays the widget settings controls on the widget panel need to form elements and for that we can call following function into the class

There we have it.Here is the demo of a widget which we have developed here.

DEMO

Download Demo
I hope this post was useful & it has helped you to create own widget in wordpress.Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (1)

  1. Nice Dude , thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to Add Tag in WordPress

Posted on 6 years ago

Bhumi

The Readers’ Poll – September 2012

Posted on 5 years ago

Bhumi