I'd like to set my WordPress (self-hosted) site up so that you can only view images if you're logged in. I want it to be impossible to view the images without being authorized as a user of the site. This plugin is exactly what I need, but it's been abandoned and no longer works.

What I want is:

  • All logged in users can view all images
  • All anonymous visitors can view no images

Something a bit more granular than the above would be nice (for example, authorizing a few specific images for public viewing,) but that's the baseline.

In essence, I want the Visibility editor, which is available for Posts and Pages:
Post/Page Visibility
..to be available for Files as well.
I want the user to be able to view a post without the images if he's not logged in.

Is there a plugin or modification that does this? Google returned nothing.

  • When you upload an image it becomes available to everybody if they know the direct image url. But I guess you mean you want to strip all the image tags in the post content (with some PHP code) for anonymous users?
    – birgire
    Jul 8, 2014 at 22:50
  • @birgire Yes, both removing the image tags from the post and denying direct accesses to them. Optimally, I'd like the images not to exist as far as guests are concerned. Jul 8, 2014 at 22:54
  • Why would you want to do this?
    – Tom J Nowell
    Jul 8, 2014 at 22:59
  • @TomJNowell Privacy concerns. None of the post text is private/confidential, but most images will be. Jul 8, 2014 at 23:07
  • 1
    The only way I know of, to restrict direct access to image urls, like http://example.com/wp-content/uploads/2014/01/cars.jpg, is to modify the webserver (apache, nginx, ... ) with authentication, for example, or stream the images through a PHP file, similar to what happened inside the ms-files.php in WordPress multisite (pre 3.5). Some other CMS store the images in the database.
    – birgire
    Jul 9, 2014 at 9:47

2 Answers 2


Have you had a look at is_user_logged_in()?

If you can explain how you're serving the photos I can perhaps suggest a way to authorize some images to be shown and the rest hidden to only logged in users.

  • How would I integrate that into a plugin? I'm not sure how to deny access to media files based on that. Jul 8, 2014 at 21:37
  • There's some confusion here. The other question you referenced is strictly for users logged in and in the dashboard. I'm not sure how that connects with your problem since anonymous visitors won't be accessing the dashboard. Are you talking about how they appear in the dashboard or restricting how they appear to users via the frontend of the website?
    – deflime
    Jul 8, 2014 at 21:44
  • I thought the post I linked to was referring to viewing images at all.. Now I see that it was actually talking about viewing from within the media upload area. Oops. Jul 8, 2014 at 21:49
  • How are you publishing the photos to the front-end for users to see them?
    – deflime
    Jul 8, 2014 at 21:53
  • I'll be uploading them via the regular Media section of the admin panel, and posting them by attaching them to posts in the normal method. Jul 8, 2014 at 22:50

If you're referring to images that are inserted into the page or post content via the editor, you could hook into the 'the_content' filter, check if the visitor is anonymous or not via is_user_logged_in(), and use a regex to remove all img tags from the_content().

I'm mobile at the moment, but I'm happy to update this a little later with some example code.

  • The concern with that approach is that the images could still be accessed via direct URL messing around.. The images should be confidential for my purposes. Jul 8, 2014 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.