By default, WordPress will create new pages for your images and other attachments. What seems like a kind gesture by WordPress at first, actually ends up being a nuisance for pretty much every business owner, with the exception of a photographer here or there.

No good deed goes unpunished. For those with themes that don’t have attachment page templates, stray media will look terrible. Even worse, that ugly attachment page could leave a bad impression with potential customers if search engines index it.

Most likely, you want your users to land on your website and see the image optimized and surrounded by other relevant content. Fortunately, there a couple different methods to quickly fix this problem and redirect attachment pages in WordPress.

Solution # 1 – Use All in One or Yoast SEO Plugin

I’m willing to bet that you already have a quality SEO plugin installed on your website.

But are you using all of its features?

Both All in One and Yoast SEO offer the option to redirect attachment pages in WordPress, helping make your site more crisp and user friendly (important for search).

All in One Instructions

  1. Login to your WordPress Dashboard
  2. Navigate to All in One SEO on left-menu
  3. Scroll down to Advanced Settings
  4. Make sure the box next to “Redirect Attachments to Post Parent” is checked
  5. Update Options

Read more on advanced features in the All in One SEO Pack.

Yoast SEO Instructions

  1. Log in to your WordPress website
  2. Navigate to SEO on left-menu
  3. Click on Advanced in Settings
  4. Click on the Permalinks tab.
  5. Enable the Redirect attachment URLs to parent post URL
  6. Save Changes

Read more on how to redirect image attachment URLs with Yoast.

Solution # 2 – Create image.php file

I’m not a big fan of using specialty plugins to patch up quick fixes. If we used a plugin to fix every little problem that WordPress presented, our websites would look like a bathroom in a hipster bar, covered in band stickers.

Plugins that are not lightweight, or essential to a WordPress website’s functionality should be removed for performance and speed considerations.

If you are not already using All in One or Yoast, skip installing a specialty, or one-trick-pony plugin. Your next best solution is to create and upload a new image.php file to redirect attachment pages in WordPress.

Note, before creating a new file, check to make sure your WordPress theme does not already have an image.php file. If the file already exists, simply add the below code to the first line:

post_parent)); ?>

Once complete, save your new or modified file and upload it into your theme directory via FTP.

Voila!