WordPress widgets are created with a bit of object-oriented programming. The WP_Widget class is extended to create each widget. The WP_Widget class includes close to 20 different methods. However, for basic widgets, you really only need to use four of them:
__construct(): registers basic widget information.
widget(): contains the widget output — what you actually see on your site front end when the widget is added to a widget area.
form(): defines the widget settings displayed in the WordPress admin area.
update(): updates widget settings when new settings are saved in the WordPress admin area.
In addition to these four methods, the
add_action function is used to tie the custom widget function to the
Here is a live example of creating Widget. Follow this snippet and adjust it according to your needs.
How useful was this post?
Click on a star to rate it!
Average rating 5 / 5. Vote count: 1