# Directory of Network Sites

> Adds a [wpide_sites_directory] shortcode that lists the public sites on the network with their names, taglines and links, cached for an hour.

- Type: PHP
- Runs: Run everywhere
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: sites, directory, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-sites-directory-shortcode/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

add_shortcode( 'wpide_sites_directory', function ( $atts ) {
    $atts    = shortcode_atts( array( 'exclude' => '' ), $atts, 'wpide_sites_directory' );
    $exclude = array_filter( array_map( 'absint', explode( ',', $atts['exclude'] ) ) );
    $key     = 'wpide_sites_dir_' . md5( implode( ',', $exclude ) );
    $html    = get_site_transient( $key );

    if ( false !== $html ) {
        return $html;
    }

    $sites = get_sites( array(
        'public'         => 1,
        'archived'       => 0,
        'spam'           => 0,
        'deleted'        => 0,
        'site__not_in'   => $exclude,
        'number'         => 500,
        'update_site_meta_cache' => false,
    ) );

    $html = '<ul class="wpide-sites-directory">';
    foreach ( $sites as $site ) {
        $tagline = get_blog_option( $site->blog_id, 'blogdescription' );
        $html   .= sprintf(
            '<li><a href="%1$s">%2$s</a>%3$s</li>',
            esc_url( $site->home ),
            esc_html( $site->blogname ),
            $tagline ? ' &ndash; <span>' . esc_html( $tagline ) . '</span>' : ''
        );
    }
    $html .= '</ul>';

    set_site_transient( $key, $html, HOUR_IN_SECONDS );

    return $html;
} );
```

## Notes

Archived, spam, deleted and search-engine-hidden sites are left out. Set exclude="1,4" to hide particular blog IDs.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Directory of Network Sites" 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/
