Can I create my own “Recent Posts” widget or customize the existing one?

I’d like to enable the Recent posts widget with the ability to show a “View All” link when there are more posts than I’ve currently got the widget set to show.

I’d also like to be able to exclude certain categories or posts from it.

Read More

Is it possible to do either via my theme’s functions.php?

(1) Customize the existing widget or (2) Create a copy of it that I can customize?

Related posts

Leave a Reply

1 comment

  1. It’s usually best to copy the existing one, name it something unique, and then add your own functionality.

    Copy the WP_Widget_Recent_Posts class from wp-includes/class-wp-widget-recent-posts.php into your functions.php (or, preferably, another file in your theme devoted just to widgets) and rename to something else, like My_Widget_Recent_Posts

    Add your functionality in there.

    Don’t forget to call register_widget('My_Widget_Recent_Posts') as part of the init phase as well.