13 March 2022

how to make custom widget in wordpress?

custom widget in wordpress?

add this code on your function.php file the last one viral-widget we added for out custom widget
function electo_store_widgets_init() {
register_sidebar( array(
'name'          => __( 'Blog Sidebar', 'electo-store' ),
'description'   => __( 'Appears on posts and pages', 'electo-store' ),
'id'            => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );

register_sidebar( array(
'name'          => __( 'Posts and Pages Sidebar', 'electo-store' ),
'description'   => __( 'Appears on posts and pages', 'electo-store' ),
'id'            => 'sidebar-2',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );
register_sidebar( array(
'name'          => __( 'Third Column Sidebar', 'electo-store' ),
'description'   => __( 'Appears on posts and pages', 'electo-store' ),
'id'            => 'sidebar-3',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );
//Footer widget areas
$electo_store_widget_areas = get_theme_mod('footer_widget_areas', '4');
for ($i=1; $i<=$electo_store_widget_areas; $i++) {
register_sidebar( array(
'name'          => __( 'Footer Widget ', 'electo-store' ) . $i,
'id'            => 'footer-' . $i,
'description'   => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );
}
register_sidebar( array(
'name'          => __( 'viral widget', 'electo-store' ),
'description'   => __( 'add custom menu for diplay name', 'electo-store' ),
'id'            => 'viral-widget',
'before_widget' => '',
'after_widget'  => '',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );

}

function.php file

register_sidebar( array(
'name'          => __( 'viral widget', 'electo-store' ),
'description'   => __( 'add custom menu for diplay name', 'electo-store' ),
'id'            => 'viral-widget',
'before_widget' => '',
'after_widget'  => '',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );


whenever you want diplay your code in wordpress add this code on your header.php  or footer.php file.

use div tag if you want to.

header or footer.php file

<?php dynamic_sidebar('viral-widget'); ?>

watch our video if you have any doubt :

No comments:

Post a Comment

If You have any doubt, or want to know about something, please let me know

how to create custom plugin deactivate hook and display all post in wordpress?

 how to create custom plugin deactivate hook and display all post in wordpress? make new folder in plugin after whatever you want your folde...