• Resolved vireshm

    (@vireshm)


    Hi,

    Hope you can help. I have been using the attachment redirect code in my child theme to redirect all media permalinks to the attachment themselves instead of to an attachment page. After the recent update, it stopped working and all permalinks now go to an attachment page. Nothing has changed on the website itself. I have a suspicion that the permissions for the theme files may have changed. What permissions are recommended in order for this redirect to work, or is there anything else I can test in order to troubleshoot?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter vireshm

    (@vireshm)

    After some more testing, we have discovered that attached files are redirecting correctly, but unattached files are going to the attachment page. Is there any way to resolve this so that unattached and attached files all redirect to the media attachment?

    Thread Starter vireshm

    (@vireshm)

    Update: Had to rollback 2 versions in order for the attachment redirect to start working again. This is obviously not ideal.. please advise on how we can get unattached (orphan) attachments to continue redirecting to the guid.. we have thousands of such docs.

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @vireshm,

    Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.

    To check if the issue is with your rank-math.php file, please try adding the filter using a different method:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/#code-snippets-plugin

    If the filter works by using the plugin, then you may need to check again the rank-math.php file in your child theme directory.

    The file permission should be the same as all your WordPress files (644).

    Let us know how it goes.

    Thread Starter vireshm

    (@vireshm)

    Hi. Please see the additional context I supplied above. We had to rollback 2 versions as the latest versions of the plugin do not use the redirect for unattached files. If the file is attached, the redirect works. We need it to work for unattached files. The inserting of the script and permissions etc is not the issue (we added the script to a rank-math.php file in the theme folder)

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @vireshm,

    We had to make some changes in the plugin code to prevent the option to redirect orphan attachments to show a blank page, so now we verify if there’s a parent post associated with the attachment before making the redirection to prevent this issue.

    The downside is that the custom filter we had before to redirect the attachments to the actual files will not work for unattached pages.

    We’ll talk with our writers to update the KB article in question to include this new information.

    Thank you.

    Thread Starter vireshm

    (@vireshm)

    Hi.

    That is unfortunate. We have over 15000 documents and images in our library so we make use of a media library plugin to create a physical folder structure within the uploads folder. This means that most of our documents are uploaded directly into these folders and are unattached.

    Seems the only recourse (if we continue using rankmath) is to switch to using direct links rather than permalinks throughout the site. Not ideal.

    Thanks

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @vireshm,

    Please try running your redirect code directly in the wp hook and see if that works for you:
    add_action( 'wp', function () { if ( ! is_attachment() ) { return; } // Code to redirect attachment. }, 10 );

    Let us know how that goes. Looking forward to helping you.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Attachment redirect stopped working’ is closed to new replies.