Add custom widget in WordPress
You can create a new widget according to your need, anywhere in the website in WordPress by adding code to one of two places.
Add below code in your functions.php file of active active.
1 2 3 4 5 6 7 8 9 10 11 |
function custom_widget() { register_sidebar( array( 'name' => 'Widget Name', 'id' => 'widget_ID', 'before_widget' => '<div class="widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="">', 'after_title' => '</h4>', ) ); } add_action( 'widgets_init', 'custom_widget' ); |
and second add the this code in your header, sidebar or any other file where you want to call that new widget.
1 2 3 4 5 |
<div id="sidebar" class="col span_3 col_last"> <?php if ( is_active_sidebar( 'widget_ID' ) ) : ?> <?php dynamic_sidebar( 'widget_ID' ); ?> <?php endif; ?> </div> |
Now go to Appearance » Widgets, here you can see you have created a new widget area, you can now put or drop any element from left panel.
[paypal-donation]