Connect with us

Plugin Tips

How to Remove All WordPress Posts Under Certain # of Views in Google Analytics

Currently trending WordPress plugins

We all know the importance of cleaning up our site from time to time to save storage space and keep our website running more smoothly. I recently had to do it for a few of my sites and wasn’t sure how to go about doing it. I concluded that if a page has not gotten even a single view registered in Google Analytics in a year or two, it is not necessarily worth keeping. I got started by going to Google Analytics and exporting my historical data.

Once there, I needed a script that reads the CSV file, ignores the URLs in it, and deletes everything else:

The idea here is simple: this script reads and matches URLs on my site with my CSV file, removes everything else. It also logs the files that have been deleted. You can modify this script to create redirects to the categories these posts were deleted from just to save time. You can even create a database dump in the same script before removing anything. Keep in mind this only “trashes” posts and doesn’t permanently delete them. You can easily restore the ones you don’t want deleted.

[more tips]

Continue Reading
You may want to check out:
*some of our articles and lists include affiliate links to fund our operations (e.g. Amazon, Elegant Themes, Envato). Please read our disclaimer on how we fund Exxponent.
You may also like...
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in Plugin Tips

To Top