-
I want to redirect attachments to the media URL in my WordPress website. I followed (https://rankmath.com/kb/redirect-attachments-to-the-media-url/) this article and it’s been working for the last 1 month, but now it’s not working. I have tried using the rollback version of Rankmath plugin but it’s not working. Please help me to resolve this issue.
-
Hello,
Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.
Can you please try clearing your website cache and check again from your end?
If that doesn’t help, please head over to your WordPress Dashboard > Settings > Permalinks and save the page without changing anything.
If the issue persists, let us know here and we will do our best to assist you further.
Thank you.
Hi Jeremy. I tried both the things you mentioned but still, my problem is the same. Please help me.
Hello,
Can you please check if the attachments are attached to some pages from your website? For attachments that are not associated with a page this feature won’t work due to the recent changes we’ve made in the plugin to prevent a blank page from appearing on some instances.
Hope this helps clarify the situation.
Don’t hesitate to get in touch if you have any other questions.
Yes, Miguel.
My attachment is not attached to any pages. But I need this feature. How can I get this feature again? Please help to regain this feature as it’s useful for me.Hello,
If the attachments are not attached to any page this is the default behavior of the plugin as of version 1.0.201, because of the changes required from the situation illustrated in the previous message.
The only way to get this working again like that would be to downgrade to version 1.0.122 but that will also lose access to the new Content AI feature and any other improvements moving forward.
Don’t hesitate to get in touch if you have any other questions.
Thanks, Miguel
I have downgraded the plugin, and now I can use that feature, but please tell me if I ever update my plugin from now on, will I not be able to use this feature?Hello,
Thank you for getting back to us. We appreciate your feedback and we are sorry for the inconvenience caused by the recent update of Rank Math.
We understand that you want to redirect unattached media attachments to their media URLs, but this feature is no longer available in the latest versions of Rank Math due to some technical issues. We had to remove this feature to prevent blank pages from appearing on some websites.
We know that this feature is important for some users, but we also have to ensure the security and performance of our plugin. That’s why we recommend that you do not use an older version of Rank Math, as it may expose your website to potential risks and bugs.
If you still want to redirect attachments that are not attached to any page, you can try using another plugin that has this feature and then disable attachment redirection in Rank Math completely. This way, you can still enjoy the benefits of Rank Math without losing the functionality that you need.
We hope this clarifies the situation and helps you resolve the issue. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again. We are always happy to help.
Thank you for choosing Rank Math!
Can you please suggest any other plugin that has this feature?
Hello,
Thank you for getting back to us.
There’s an old plugin on the WordPress repository that might work, but please note that we have not tested this plugin, and take no responsibility over its use.
We hope this helps you resolve the issue. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again. We are always happy to help.
Thank you for choosing Rank Math!
Hi again,
Following up on this with additional information.
You can use this code to redirect attachments that are unattached to your homepage, i.e. the attachment page will be redirected to the homepage only if the attachment has no parent post or the parent post does not exist. Otherwise, it will be redirected to the parent post as usual.
function attachment_redirect() { global $post; if ( is_attachment() && ( $post->post_parent == 0 || !get_post($post->post_parent) ) ) { wp_redirect( home_url(), 301 ); exit(); } } add_action( 'template_redirect', 'attachment_redirect' );
You can learn how to add this code to your website here: https://rankmath.com/kb/wordpress-hooks-actions-filters/
We hope this helps you resolve the issue. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again. We are always happy to help.
Thank you for choosing Rank Math!
I don’t want to redirect attachments to the homepage that has no parent post. I want to redirect those attachments to the media directly, without auto auto-generated page.
Hello,
I understand that you want to redirect attachments directly to their media URLs without generating an intermediate attachment page. To achieve this, you can use the following code:
function redirect_attachments_to_media_url() { if ( is_attachment() ) { $attachment_url = wp_get_attachment_url(); if ( $attachment_url ) { wp_redirect( $attachment_url, 301 ); exit(); } } } add_action( 'template_redirect', 'redirect_attachments_to_media_url' );
This code checks if the current page is an attachment page and, if so, redirects it directly to the media URL. It should work to achieve the behavior you desire.
Please make sure to backup your website before making any changes to your theme files or adding custom code.
Let us know how this goes. Please let us know if you have further questions or concerns.
Thank you.
Thanks, Ike
It is working great for me.Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.
The ticket ‘Redirect Attachments to the Media URL’ is closed to new replies.