WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
For further reading, the Widgets API is a helpful resource. – onemanarmy Nov 9 '12 at 21:48
up vote 14 down vote accepted

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/default-widgets.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.

share|improve this answer
+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 Oct 13 '11 at 20:38
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 Oct 13 '11 at 20:43
To init my widget I had to add add_action( 'widgets_init', create_function( '', 'register_widget( "My_Widget_Recent_Posts" );' ) ); to functions.php. – onemanarmy Nov 9 '12 at 21:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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