Creating a Custom WordPress Widgets

| Last Updated: | In: WordPress


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!


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:


, ,