Redirect Image Attachments Links to Parent Post

It’s not wise to index your image attachment pages in search engines. In this post, I will show you how to redirect image attachments links to the parent post.

But if you have done it mistakenly and now like to disable it then check this post. You don’t have to manually remove image link one by one. 

Let me show you two different method which will help you to redirect your image attachment pages. 

After login to Cpanel, navigate to your active theme directory. Search for function.php file and open this file via editor. Copy the following code and paste it inside your function.php file. 

					// Remove attachments
add_action('template_redirect', 'jltwp_adminify_remove_attachment');
function jltwp_adminify_remove_attachment()
    if (is_attachment()) {

        global $post;

        $url = get_the_permalink($post->post_parent);
        $status = '301';

        wp_redirect($url, 301);

Save the file and check any attachment page. I hope it will redirect you to the parent post. 

Redirect Media Attachment URL

You can do the same configuration from the WordPress dashboard using WP Adminify plugin. If you have properly activated the plugin then click on WP Adminify option from your dashboard menu. 

Navigate to Tweaks > Attachments

Search for Disable Attachments option and enable it. That’s how you can disable image link from your website dashboard.

Redirect attachment pages archives to parent post URL

That’s all about media redirection to original page or post tweaks. 

Was this article helpful?

© 2021-2024 - Adminify | All rights reserved

WP Adminfy accepted payment methods