This free Plugin for WordPress and ClassicPress allows you to remove the automatically generated Attachment Pages
WordPress and ClassicPress automatically generate a page for every file you upload to your Media Library. Even if you do not want to use these pages and never link media files to their attachment page these pages exist and can be accessed by their automated generated URL.
The Smart Attachment Page Remove Plugin blocks access to Attachment Pages. You don’t have to change anything, the plugin works out of the box.
When someone tries to access an attachment page The Smart Attachment Page Remove Plugin causes an 404 error (“Not found”). Optionally, a status code 410 (“Gone”) can be sent instead of status code 404. This is recommended.