Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove parent widget and sidebar in child theme wordpress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 684
    Comment on it

    Hello Everyone, In this blog I teach you How to remove parent widget and sidebar in child theme wordpress. Below code is the parent theme sidebar code.

    class PWidgetName extends WP-Widget {
        // your widget code
    }
    

    You can remove this code or overwrite the widget code in child theme, just copy the below code and put into your child theme functions.php file

    add-action( 'widgets-init', 'wp-tuts-parent-unregister-widgets', 10 );
    
    function yoga-parent-unregister-widgets() {
    
        unregister-widget( 'PWidgetName' );
        register-widget( 'MyCustomWidget' );
    }
    
    class MyCustomWidget extends WP-Widget {
        // Child Custom Widget code
    }
    

    Below code is the parent theme sidebar code.

    class ParentWidgetName extends WP-Widget {
        // your widget code
    }
    function yoga-widgets-init()
    {
        register-sidebar( array(
            'name' => _-( 'Main Sidebar', 'yoga' ),
            'id' => 'sidebar-1',
            'description' => _-( 'Widgets in this area will be shown on all posts and pages.' ),
            'before-widget' => '<div class="widget %2$s">',
            'after-widget'  => '</div>',
            'before-title'  => '<p>',
            'after-title'   => '</p>',
        ) );
    }
    /** Register sidebars by running pinboard-widgets-init() on the widgets-init hook. */
    add-action( 'widgets-init', 'yoga-widgets-init' );
    

    You can remove this code or overwrite the sidebar code in child theme, just copy the below code and put into your child theme functions.php file

    add-action( 'widgets-init', 'wp-tuts-parent-unregister-sidebars', 10 );
    
    function yoga-parent-unregister-sidebars() {
    
        unregister-sidebar( 'sidebar-1' );
    }
    

    Hope it helps you. Thank-you readers!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: