# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, archives, sidebar
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/archives-widget-options/

## Code

```php
// 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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Archives Widget: Yearly Links and a Limit" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
