# Remove Sample Content From New Network Sites

> Deletes the "Hello world!" post, its sample comment and the "Sample Page" from each newly created site so site owners start with a clean slate.

- Type: PHP
- Runs: Run everywhere
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: new-site, defaults, cleanup
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-new-site-remove-sample-content/

## Code

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

add_action( 'wp_initialize_site', function ( $site ) {
    switch_to_blog( $site->blog_id );

    foreach ( array( 'hello-world' => 'post', 'sample-page' => 'page' ) as $slug => $type ) {
        $found = get_posts( array(
            'name'           => $slug,
            'post_type'      => $type,
            'post_status'    => 'any',
            'posts_per_page' => 1,
            'fields'         => 'ids',
            'no_found_rows'  => true,
        ) );

        if ( $found ) {
            wp_delete_post( $found[0], true ); // Also removes its comments.
        }
    }

    restore_current_blog();
}, 200 );
```

## Notes

Only runs once, right after a site is created; it matches the sample items by their default slugs.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Sample Content From New 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/
