How to Redirect Attachment URLs to Parent Post/Page URL in WP?

 

Have you noticed that whenever you upload a file to the WordPress media library, for example, an image, WordPress creates a separate media attachment page for each one of these files? The newly created media attachment page only contains media content along with its own automatically generated URL.

Such pages are not beneficial because they send a message to search engines that the page has thin content. For this reason, they have to be redirected from WordPress attachment pages to the page where the file is attached to.

Why should you redirect WordPress attachment pages?

For example, you create a post that includes three images. WordPress will create four URLs for these images – three for the images and one for the original post. This can affect your SEO in the following ways.

  • Search engines may direct more traffic to the attachment pages instead of the original page they live on/belong to.
  • The attachment will appear separate and out of context. When a visitor lands on the image or attachment page, they will close it and move away thereby increasing bounce rates.
  • There is a possibility of the image files being considered as duplicate content.

How to redirect WordPress attachment pages?

You can resolve this issue by redirecting the attachment to the post or page they belong to. It can be done via WordPress plugins or through your own code snippets.

1. Yoast SEO plugin

 

In Yoast SEO, click on SEO option and

  • Go to search console
  • Then, click on media tab
  • Make sure to check ‘yes’ for the ‘Redirect attachment URLs to the attachment itself’
  • Save the changes.

Once you do this, all the WordPress media attachment pages will be redirected to the parent post or page.

Remember, this will work only if the media was initially attached to a post or page.

On March 6th 2018, Yoast rolled out an update where a bug affected the rankings of some websites. In case you experienced a ranking drop after March 6th your website may be affected by the Yoast SEO bug.

Here is the official description of the bug problem.

‘The bug was simple yet very painful: when you updated from an earlier version of Yoast SEO to Yoast SEO 7.0-7.0.2 (specifically those versions), we would not always correctly convert the setting you had for the old setting into the new one. We accidentally set the setting to ‘no’. Because we overwrote the old settings during the update, we could not revert this bug later on.’

The founder of the Yoast, Joost De Valk added,

This post serves both as a warning and an apology. We want to ask all of you to check whether your settings for the redirect of the attachment URLs are correct. And, for those of you who suffered from a decrease in rankings because of incorrect settings, we offer a solution that Google has OKed as well.

We recommend you to go through the official announcement by Yoast to apply the suggested solutions if you were affected by the bug

 

2. All In One SEO

 

In case you’re using ‘All in One SEO Pack’ not to worry. Here is the solution. Go to ‘general settings’ and check the box ‘Redirect Attachments to Post Parent.’

 

3. For WordPress websites that don’t use plugins

It is also possible to redirect WordPress attachment pages to the original post using only code. You have to add this code to the image.php file.

<?php wp_redirect(get_permalink($post->post_parent)) ; ?>

Once you add the code, save it and upload it to the root directory of your child theme.

Independent media pages will be suitable for photographers and graphic designers. But for other WordPress users, redirecting the attachments to the post or pages they belong is the right call.

 

If you have any further questions about the process, feel free to contact us anytime.

 

Recent Posts

A Review of Booker Customer Relationship Management (CRM) Software for Medical Spas

Ratings: 4.1 Stars (Capterra) | 4.1 Stars (GetApp) Booker by Mindbody is a prominent CRM…

1 week ago

Top 3 Affiliate Software Picks for Easy Integration

Affiliate marketing software offers a smart and convenient solution for businesses to refine their marketing…

2 weeks ago

Accountability Chart 101: A Must-Have Tool for Medical Practice Management

For medical practices, where a single client’s experience relies on multiple team members working in…

2 weeks ago

Most Popular Screen Resolutions in the US

When creating and optimizing a website, one of the most important factors that some businesses…

1 month ago

How to Effectively Supercharge Healthcare Marketing with Patient Personas

One of the biggest challenges in creating an effective healthcare marketing strategy is recognizing that…

1 month ago

How To Take Better Photos For Clinics Specializing in Vaginal Rejuvenation

As more women become increasingly interested in vaginal rejuvenation, having appropriate and professional vaginal rejuvenation…

2 months ago