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 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.


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.

Share on Facebook0

Share on LinkedIn0Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit0

Comments (1)

  1. Nice Dude , thank you

Leave a Reply

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

Most Popular Posts

How to use Session Save Path in PHP

Posted on 5 years ago


How To use Singleton Design Pattern in PHP

Posted on 5 years ago


An Introduction to Gulp JS

Updated 1 month ago


Getting started with Laravel

Updated 1 month ago


How to use Git init command

Updated 1 month ago


The Reader’s Poll – June 2015

Posted on 2 years ago


The Reader’s Poll – August 2014

Posted on 3 years ago


The Reader’s Poll – June 2014

Posted on 3 years ago


The Readers’ Poll – May 2014

Posted on 3 years ago


The Readers’ Poll – August 2013

Posted on 4 years ago