• Tk808

    (@tk808)


    Alright, i have over 8500 files uploaded to several pages in my wp site. All the files are media links, which is the direct download from the page they are on.

    I want to convert all those media files and link them back to their attachment pages without doing all 8500 files manually

    One solution could be redirecting the media file to the corresponding attachment ID. But i’m totally lost, need any information to get me pointed in the correct direction.

    Cheers!

    [Moderator Note: No bumping. If it’s that urgent, consider hiring someone.]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Ryan Hellyer

    (@ryanhellyer)

    I need exactly the same functionality. If you find a solution, please post back here with the answer ??

    Ryan Hellyer

    (@ryanhellyer)

    This should be possible to do in an automated fashion. The URLs used by WordPress look like <a href="$URL" so we should be able to write a plugin which parses that for each media file URL attached to the post, then string replace it and resave it into the database via wp_update_post().

    I’m hoping some kind soul out there has already written such a tool though as I’m keen to avoid writing it myself :/

    Thread Starter Tk808

    (@tk808)

    Here is an update of what i’ve found Ryan.

    Function for direct media file links falls under ” Wp_Get_… “
    That can be found in WP-Includes/post-template.php

    https://codex.www.ads-software.com/Function_Reference/wp_get_attachment_url

    and
    Functions for attachment page files falls under just ” Get_…
    Which can be found in WP-Includes/link-template.php

    https://codex.www.ads-software.com/Function_Reference/get_attachment_link

    Basically, you are going to force attachment pages on the media file links. I’ll keep looking into it.

    Ryan Hellyer

    (@ryanhellyer)

    Yep, that sounds about right. Unfortunately it’s putting all that together into something which can automate the changeover for us that is time consuming.

    I had a good Google around for this and asked on Twitter, but no one was able to help. So I might end up writing a plugin to do this myself. I have some things to do tonight, but if I can get them done quickly then I might tackle this tonight before I go to bed. If I don’t do it this evening then it will likely need to wait a few months as I’m about to move to Germany and I’m sure I’ll have lots of distractions there which will stop me from doing this upgrade (I’ve been thinking about doing this for a REALLY long time now).

    Ryan Hellyer

    (@ryanhellyer)

    Here’s a very crude hack which does what you want … https://geek.ryanhellyer.net/products/media-file-attachment-page-converter/

    If you have lots of posts it will explode. I have lots of posts on my own site, so I still need to set it up to iterate through each post individually to ensure that it will eventually process all my posts. I don’t think I’ll get that completed any time soon though.

    Ryan Hellyer

    (@ryanhellyer)

    I tested this out on a unimportant blog of mine and it worked perfectly … https://random.ryanhellyer.net/

    I also tested it on my local server with my biggest site with over 500 posts and thousands of images and it worked fine on that too, so I’m probably not going to bother with designing it to scale up after all.

    Ryan Hellyer

    (@ryanhellyer)

    This has worked really well on my own site … https://ryanhellyer.net/

    I made a few changes since I posted last, to correct for issues when using it with domain mapped multisite installs.
    https://geek.ryanhellyer.net/products/media-file-attachment-page-converter/

    Hopefully this does what you are trying to achieve ??

    The only issue I found is that most of my older images are not attached to their posts, so they were not converted. So now I need another plugin to automatically attach images to posts :/

    Thread Starter Tk808

    (@tk808)

    Hey man, i totally appreciate all your time and effort into writing that code/plugin.

    So I tested your code and inserted it into a php file, installed it like a plugin and activated it through the URL link you had posted on your awesome site… unfortunately, no success.

    I’ll give it a shot again tomorrow though, maybe i overlooked something.

    On a side note, all my files are currently attached to pages and are RAR and ZIP files, so maybe image files are having a different effect.

    Cheers dude and good luck in Germany!

    Ryan Hellyer

    (@ryanhellyer)

    Am I able to see an example of the site so I can see what the links look like?

    Thread Starter Tk808

    (@tk808)

    radrom.com

    I’m about to give your plugin another go, i’ll keep you updated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Transform Media Files back into Attachment pages’ is closed to new replies.