Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to add custom widgets?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #294081
    amandajames
    Participant

    I am adding the following code to functions.php

    function wpblog_widget()
    {
        register_sidebar(array(
            'name' => __('Primary Sidebar', 'wpb'),
            'id' => 'primary_sidebar', // unique-sidebar-id
            'description' => '',
            'class' => '',
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));
    
    }
    
    add_action('widgets_init', 'wpblog_widget');
    

    This is to register a widget and to make the widget area visible I am dding this code in sidebar.php

    <?php if ( is_active_sidebar( 'Primary Sidebar' ) ) : ?>
    
        <?php dynamic_sidebar( 'Primary Sidebar' ); ?>
    
    <?php endif; ?>
    

    I don’t know why it is not working? I have seen the code here https://www.wpblog.com/how-to-add-custom-widget-area-to-wordpress-themes/

    #294117
    uxfed
    Participant

    Is your widget position showing in the backend? And if so, what have you tried to include in that widget position?

    #296515
    farbyte
    Participant

    I think you should be extending the WP_Widget class.
    This tutorial looks pretty good:
    https://kinsta.com/blog/create-wordpress-widget/

    #302136
    priyagchaudhary
    Participant

    I am trying to say yo just add some step , i hope you can add custom widgets
    Create your widget’s class by extending the standard WP_Widget class and some of its functions.
    Register your widget so that it’s made available in the Widgets screen.
    Make sure that your theme has at least one widget area in which to add the widgets.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.