How to extend a custom widget in wordpress?

别来无恙 提交于 2019-12-12 02:57:42


I am talking about making a widget which extends a child widget of WP_Widget.

Using this as reference:


My_WidgetBase extends WP_Widget

My_Widget extends My_WidgetBase

I want to know how to get My_Widget to show up with my other widgets (it is not currently). I have gotten My_WidgetBase to work.

This is important for my framework. I understand that widget(), update(), and form() must be overridden, but I could not find anything about making a grandchild of WP_Widget anywhere.


class My_WidgetBase extends WP_Widget {

    public function __construct($id = 'my-widget-base', $desc = 'My WidgetBase', $opts = array()) {
        $widget_ops = array();
        parent::__construct( $id, $desc, $widget_ops );

    public function widget( $args, $instance ) {
        die('function WP_Widget::widget() must be over-ridden in a sub-class.');

    public function update( $new_instance, $old_instance ) {
        return $new_instance;

    public function form( $instance ) {
        echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
        return 'noform';


    function RegisterMyWidgets() {

add_action( 'widgets_init', 'RegisterMyWidgets' );


Solved digging further into this thread:

The problem was not with my implementation of the classes, but how I included the parent in my framework. I was not working with both child and grandchild in the same php file, but two separate files with different directories.

Solving this problem was a matter of using require_once() correctly in the directory of my grandchild class.