How to create widget in wordpress
How to create widget in wordpress
How to create widget in wordpress
To understand widgets in WordPress: Widgets are modular pieces of content that perform a specific task, providing an easy way to add features and features to your website without getting bogged down in complicated coding WordPress offers a variety of pre-defined widgets, but that it will monetize your site to meet specific needs by creating custom widgets You can do that.
In theme root directory write below code in functions.php
function custom_widget_area() { register_sidebar(array( 'name' => 'Footer Area One', 'id' => 'custom_widget_one', 'description' => 'Add widgets here to appear in the custom widget area.', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>', )); } add_action('widgets_init', 'custom_widget_area');
It will display under Appearance widgets section
More info How to create widget in wordpress
class Custom_Widget extends WP_Widget { public function __construct() { parent::__construct( 'custom_widget', 'Custom Widget', array('description' => 'A customizable widget for your site.') ); } // Widget front-end public function widget($args, $instance) { echo $args['before_widget']; echo '<div class="custom-widget">'; echo $args['before_title'] . 'Your Widget Title' . $args['after_title']; echo '<p>Your widget content goes here.</p>'; echo '</div>'; echo $args['after_widget']; } // Widget backend public function form($instance) { // Widget form fields } // Update widget settings public function update($new_instance, $old_instance) { // Update widget settings } } // Register the widget function register_custom_widget() { register_widget('Custom_Widget'); } add_action('widgets_init', 'register_custom_widget');