Title: Automatic Sample Page Delete
Last modified: August 22, 2016

---

# Automatic Sample Page Delete

 *  Resolved [2shaynez](https://wordpress.org/support/users/2shaynez/)
 * (@2shaynez)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/automatic-sample-page-delete/)
 * I just went through hell after updating to 4.1
    I’ve worked out all my kinks 
   except for 1
 * for the past year I have been using this piece of code in my theme’s functions.
   php (minus the backtics ` obviously) to automatically delete my sample page every
   time I make a new site:
 * 5 `// Find and delete the WP default 'Sample Page'`
    6 `$defaultPage = get_page_by_title('
   Sample Page' );` 7 `wp_delete_post( $defaultPage->ID );`
 * However, all of a sudden, I am getting this error:
    Notice: Trying to get property
   of non-object in ../wp-content/themes/Nuvellen/functions.php on line 7
 * I just did a test by making a new site, and it does delete the sample page, but
   I can’t figure out why it would give me this error all of a sudden
 * Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [jkhongusc](https://wordpress.org/support/users/jkhongusc/)
 * (@jkhongusc)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/automatic-sample-page-delete/#post-5662913)
 * You should do a check to see that defaultPage is not empty before you attempt
   to delete it. That is most likely your problem. The sample pages was deleted;
   and the next time the code is run it attempts to delete a non-object.
 *  Thread Starter [2shaynez](https://wordpress.org/support/users/2shaynez/)
 * (@2shaynez)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/automatic-sample-page-delete/#post-5663028)
 * Is defaultPage defined anywhere else, perhaps within the default wordpress files.
   I keep this at the top of my functions.php on numerous 1000+ site networks and
   never had a problem. I get what you mean by it running and trying to find something
   that isn’t there but it wouldn’t make sense that I’ve never had this problem 
   before. Also that would defeat the purpose of this widely used script…
 *  Thread Starter [2shaynez](https://wordpress.org/support/users/2shaynez/)
 * (@2shaynez)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/automatic-sample-page-delete/#post-5663052)
 * Solution: I had wp-debug set to true when trying to battle multiple bugs after
   updating to 4.1. Forgot to switch back to false, fixed her right up!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Automatic Sample Page Delete’ is closed to new replies.

## Tags

 * [automatically](https://wordpress.org/support/topic-tag/automatically/)
 * [delete](https://wordpress.org/support/topic-tag/delete/)
 * [multisite](https://wordpress.org/support/topic-tag/multisite/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [sample page](https://wordpress.org/support/topic-tag/sample-page/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 3 replies
 * 2 participants
 * Last reply from: [2shaynez](https://wordpress.org/support/users/2shaynez/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/automatic-sample-page-delete/#post-5663052)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
