Creating a Custom WordPress Widgets

WordPress widgets provides a simple way of giving any information of your website users. It can be easily dragged and dropped in your widget area. Navigate to the Appearance » Widgets section in your WordPress dashboard to get the list of available widgets. Creating a WordPress widgets is just like creating a WordPress plugin. It’s easier to code than a plugin which can have more than one file. Below are the major functions to create your own widgets.

The WP_Widget class is located in wp-includes/widgets.php

Register your own widget using the widgets_init hook:

Update WordPress Widgets Data

You can update your widget data by using admin panel. Use bellow code snippets :

Display WordPress Widgets on Frontend

After update your data from admin section, use bellow code snippets to display the output :

Complete Example for the widget

Open functions.php file from your current activated theme and copy bellow code and paste it to the end of code. Now go to Appearance » Widgets section in your WordPress dashboard and you will see your widget available there.

It’s easier to copy and paste. Have fun!

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , ,