Archives Widget: Yearly Links and a Limit
Changes the classic Archives widget to list years instead of months and caps how many entries it shows, keeping the sidebar short on old blogs.
Opens WPIDE on
Code
// yearly, monthly or weekly.
$wpide_archives_widget_type = 'yearly';
// Maximum number of links (0 = all).
$wpide_archives_widget_limit = 10;
$wpide_archives_widget_args = function ( $args ) use ( $wpide_archives_widget_type, $wpide_archives_widget_limit ) {
$args['type'] = $wpide_archives_widget_type;
if ( $wpide_archives_widget_limit > 0 ) {
$args['limit'] = (int) $wpide_archives_widget_limit;
}
return $args;
};
add_filter( 'widget_archives_args', $wpide_archives_widget_args );
add_filter( 'widget_archives_dropdown_args', $wpide_archives_widget_args );
Notes
Set the type to monthly to keep months and only apply the limit.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.