# Archives List Shortcode

> Adds an [archives] shortcode that lists your posts by month or year, as a list or a dropdown, anywhere in content or widgets.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: shortcode, archives, dates
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/archives-list-shortcode/

## Code

```php
add_shortcode( 'archives', function ( $atts ) {
    $atts = shortcode_atts( array(
        'type'       => 'monthly',
        'limit'      => '',
        'show_count' => 'no',
        'dropdown'   => 'no',
        'post_type'  => 'post',
    ), $atts, 'archives' );

    $args = array(
        'type'            => in_array( $atts['type'], array( 'yearly', 'monthly', 'weekly', 'daily', 'postbypost', 'alpha' ), true ) ? $atts['type'] : 'monthly',
        'limit'           => $atts['limit'] ? absint( $atts['limit'] ) : '',
        'show_post_count' => 'yes' === $atts['show_count'],
        'post_type'       => post_type_exists( $atts['post_type'] ) ? $atts['post_type'] : 'post',
        'echo'            => false,
    );

    if ( 'yes' === $atts['dropdown'] ) {
        $args['format'] = 'option';

        return '<select class="wpide-archives-dropdown" aria-label="Archives" onchange="if(this.value){window.location.href=this.value;}"><option value="">Select a period</option>' . wp_get_archives( $args ) . '</select>';
    }

    return '<ul class="wpide-archives">' . wp_get_archives( $args ) . '</ul>';
} );
```

## Notes

Example: [archives type="yearly" show_count="yes"] or [archives type="monthly" limit="12" dropdown="yes"].

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Archives List Shortcode" 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/
