0

My goal is to create a new recent post widget, Wordpress has one by default and i know how to edit it, but i was thinking i want to let the user decide what recent post suits most to his needs.

Is there any way to create a new recent post Widget without overriding the wordpress default one?

0

My widget was like this:

 public function __construct() {
    $widget_ops = array(
        'classname' => 'yggdrasil_widget_recent_entries',
        'description' => __( 'Your site’s most recent Posts.' ),
        'customize_selective_refresh' => true,
    );
    parent::__construct( 'recent-posts', __( 'Recent Posts' ), $widget_ops );
    $this->alt_option_name = 'yggdrasil_widget_recent_entries';
}

Below works as a new widget without overriding the default wordpress recent posts

 public function __construct() {
    $widget_ops = array(
        'classname' => 'yggdrasil_widget_recent_entries',
        'description' => __( 'Your site’s most recent Posts.' ),
        'customize_selective_refresh' => true,
    );
    parent::__construct( 'yggdrasil-recent-posts', __( 'Yggdrasil Recent Posts' ), $widget_ops );
    $this->alt_option_name = 'yggdrasil_widget_recent_entries';
}

to not override default recent post the only thing i have to do is not name it as 'recent-posts' on this line: parent::__construct( 'recent-posts', __( 'Recent Posts' ), $widget_ops );.

The error was there.

see more details at: https://codex.wordpress.org/Widgets_API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.