Plugin Tips
How to Remove All WordPress Posts Under Certain # of Views in Google Analytics
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.
