How to Create Widget in WordPress using PHP Code

Widget in wordpress will be more helpful for non-developer, widget can be create easily with simple steps. Widgets are the important advantage in wordpress, . Here is the tutorial for how to create widget in wordpress using php code.
function wearecoders_plugin() – this function will create the widget name as “wearecoders Widget”
function form() – this function will be used to display the content to Admin area

function widget() – this function will be used to display the content to visitor area
Add the below coding into your functions.php

class wearecoders_plugin extends WP_Widget
{
function wearecoders_plugin()
{
parent::WP_Widget(false, $name = __('Wearecoders Widget', 'wearecoders_plugin') );
}
function form()
{
echo "<b>This is sample widget</b>";
}
function widget()
{
echo "<b>This is sample widget</b>";
}
}
add_action('widgets_init', create_function('', 'return register_widget("wearecoders_plugin");'));
(Visited 50 times, 1 visits today)

Leave a Comment.