modify a output of a widget

I’m to implement a theme in wordpress.

Is possible modify a output (html) of widget in wordpress?

For example, the “recent comments widget”?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I would copy the widget from the core as needed, put it in the theme or plugin, but you should also unregister the core widget you are replacing.

That can be done like this:

// unregister all default WP Widgets
function unregister_default_wp_widgets() {
    unregister_widget('WP_Widget_Pages');
    unregister_widget('WP_Widget_Calendar');
    unregister_widget('WP_Widget_Archives');
    unregister_widget('WP_Widget_Links');
    unregister_widget('WP_Widget_Meta');
    unregister_widget('WP_Widget_Search');
    unregister_widget('WP_Widget_Text');
    unregister_widget('WP_Widget_Categories');
    unregister_widget('WP_Widget_Recent_Posts');
    unregister_widget('WP_Widget_Recent_Comments');
    unregister_widget('WP_Widget_RSS');
    unregister_widget('WP_Widget_Tag_Cloud');
}
add_action('widgets_init', 'unregister_default_wp_widgets', 1);

Then register your new widget and you should be all set.


If you just need to change the aesthetics of a widget and not the functionality – you could try using Javascript to manipulate the elements as needed.

Method 2

Yes, you can modify the output of the widget, but not by modifying core files. What I would do is, go into the wp-includes/default-widgets.php and copy the entire widget code and rewrite it as you need it. I would also then paste the following into your functions.php file. That way the WP default one doesn’t show up in the admin. Also, make sure to use a different class name for the new widget.

wp_unregister_sidebar_widget( 'recent-posts' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x