Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ouput url of WordPress [Gallery] Shortcode

I recently installed ta plugin that now uploads my images from the media library to s3.

I have also FTP's the entire uploads folder to s3 which encompasses about 4000 images.

I have used throughout my site the wordpress gallery shortcode however somewhere and somehow it outputs the siteurl.

How do I change this so that I can override the url to be the one from my S3 bucket?

I will admit I have no idea what I am doing here or where to start and I really will appreciate your help :)

like image 470
JamesG Avatar asked Jan 19 '17 18:01

JamesG


People also ask

How do I use WordPress gallery shortcodes?

Basic Usage To get started with the [gallery] shortcode go to Posts section and add a New Post which we will call "Gallery Post". In the editor area place the shortcode [gallery] (in either the Visual/HTML View). After that press Publish/Update.

How do I change my WordPress gallery?

When you click any area of the image gallery, icon buttons appear top of the area. At any time, you can edit the images or settings of your gallery by clicking on the Edit button. You can remove the image gallery at any time by clicking on the Remove button.


1 Answers

You can filter images src attribute output and replace old url with new url as follow. copy below code to your theme functions.php 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);
like image 188
Alireza Hoseinzadeh Avatar answered Nov 13 '22 04:11

Alireza Hoseinzadeh