admin管理员组

文章数量:1399997

Currently my videos are hosted within my wp installation. I want to move all videos to my new server.

Currently, my media url are as follows .mp4

I am moving all videos to my central media server which will have this new url .mp4

My site will continue to be hosted where it is right now. I will only move media files.

I was hoping Velvet Blues Update URLs will be up for the job but it does not find any url to update on my website.

Probably because I am using JW player on my site and JW player post video using shortcode and ID only on the post area.

[jwplayer mediaid="13441"]

No URL on the post. Maybe this is the reason why velvet blue is not picking up the URLS to update.

Having said that, is there a way to update all media urls in wordpress install from the media library as if it was added as external url?

Which database entries holds the media URL? I am guessing my last resort will be to run find and replace on my database.

Any suggestion will be highly appreciated.

Thanks

Currently my videos are hosted within my wp installation. I want to move all videos to my new server.

Currently, my media url are as follows http://mysite/wp-content/uploads/video01.mp4

I am moving all videos to my central media server which will have this new url http://media.mysite/videos/video01.mp4

My site will continue to be hosted where it is right now. I will only move media files.

I was hoping Velvet Blues Update URLs will be up for the job but it does not find any url to update on my website.

Probably because I am using JW player on my site and JW player post video using shortcode and ID only on the post area.

[jwplayer mediaid="13441"]

No URL on the post. Maybe this is the reason why velvet blue is not picking up the URLS to update.

Having said that, is there a way to update all media urls in wordpress install from the media library as if it was added as external url?

Which database entries holds the media URL? I am guessing my last resort will be to run find and replace on my database.

Any suggestion will be highly appreciated.

Thanks

Share Improve this question asked Nov 22, 2014 at 11:57 Charles WayneCharles Wayne 2852 gold badges4 silver badges11 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 4

is there a way to update all media urls in wordpress

I had a similar issue with my media files not having the correct file location after a Wordpress upgrade (somehow all the media links switched to a crazy incorrect directory), so I found Upload URL and Path Enabler which was able to rewrite all media URLs to a different path location where all my media was actually being stored.

Hope that helps someone else too!

I think you can create custom function to replace your old wp_attachment_url.

Assume you have same file name on your new media url, so you can add filter for jw player plugins only, something like this:

 if ( has_shortcode( get_the_content(), 'jw_player' ) ) { 
     function mynewmediaurl($wp_get_attachment_url){
$newmediadir = 'http://yourdomain/video/';
    $filename = basename($wp_get_attachment_url );
    $newurl = $newmediadir.$filename;
        return $newurl;
        }
    add_filter('wp_get_attachment_url', 'mynewmediaurl');
    }

you can add in your functions.php

Reference:

https://codex.wordpress/Function_Reference/has_shortcode

https://developer.wordpress/reference/functions/wp_get_attachment_url/

https://codex.wordpress/Plugin_API/Filter_Reference/wp_get_attachment_url

https://developer.wordpress/reference/functions/get_attached_file/

Use WP-CLI's search-replace command to locate database entries with the old URL and replace them with the new one. You also can do a --dry-run to see how many entries are affected.

$ wp search-replace 'http://example/wp-content/uploads/' 'http://media.example/videos/' --dry-run

Assuming that there are limited video in your site. you can replace URL by do following :

Expert your site database , Replace URL and import again. This is safe way to replace URL. You can do same thing using sql query also but that can cause problem sometime.

本文标签: Update media file url in wordpress media library