Change urup url WordPress [Gallery] Shortcode

I recently installed the ta plugin, which now downloads my images from the media library to s3.

I also have FTP the entire download folder on s3, which includes about 4000 images.

I used a short link on my site in the wordpress gallery, but somewhere and somehow it displays the site.

How do I change this so that I can redefine the url so that it is one of my S3 buckets?

I admit that I have no idea what I'm doing here or where to start, and I will really be grateful for your help :)

+5
source share
3 answers

You can filter the output of the src attribute of images and replace the old url with the new URL, as shown below. copy the code below into your functions.php theme and replace www.oldurl.com and www.newurl.com with your own urls.

 add_filter('wp_get_attachment_image_src', function ($image) { if(is_array($image)){ $image[0] = str_replace('www.oldurl.com', 'www.newurl.com', $image[0]); } return $image; }, 999); 
+2
source

Looking in wp_get_upload_dir() for a wrapper for wp_upload_dir() , which again is a wrapper for _wp_upload_dir() , we see that the download URL can be changed using the upload_url_path option.

Since you are moving all your downloads to S3, you can try adding your base url in S3 to the upload_url_path parameter.

You must first test this in your dev installation, just to see how it works with your current setup.

+2
source

You might want to search and replace through the database.

Here you can see how to make a SQL query to change the image path in posts: 13 useful WordPress queries

 UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="http://www.oldsiteurl.com', 'src="http://yourcdn.newsiteurl.com'); UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://yourcdn.newsiteurl.com') WHERE post_type = 'attachment'; 
+1
source

Source: https://habr.com/ru/post/1263071/


All Articles