How to: Hide All Old Images in WordPress without Deleting Them Using functions File


Tip: 20 ways to drive more traffic to your site

Most of us have a lot of old images on our website that are outdated or need to be removed for some reason. You can try to do it manually but that can take a lot of effort. If you just delete them without removing their links in your posts, it could affect user experience. The good news is you can use your functions file to do it.

The idea here is simple: you will have to create a class that hides images. Your function should also apply them to IMG elements in your posts. You will want to make sure your function only targets posts that are too old. This code snippet also makes sure only posts are targeted and not pages. Just add this to your functions file and change the date. This particular code hides images posted before August of 2024.

 

More WordPress reading: