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.

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?

  • 1
    For further reading, the Widgets API is a helpful resource.
    – manafire
    Commented Nov 9, 2012 at 21:48

1 Answer 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.

  • +1 Sweet. Ok, I added it to a special custom widgets file I have that's "included" via "require_once()" in my functions.php. However, although I changed the classname, it appears to take over the default WP Recent Posts widget. Any ideas?
    – N2Mystic
    Commented Oct 13, 2011 at 20:38
  • 2
    You must assign a unique name to the widget. parent::__construct('recent-posts', __('Recent Posts'), $widget_ops); 'recent-posts' should be changed to something like 'my-recent-posts' , and you should also change the label to something that makes the widget identifiable as yours: 'My Recent Posts'
    – Bendoh
    Commented Oct 13, 2011 at 20:43
  • 3
    To init my widget I had to add add_action( 'widgets_init', create_function( '', 'register_widget( "My_Widget_Recent_Posts" );' ) ); to functions.php.
    – manafire
    Commented Nov 9, 2012 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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