Modify featured image path to Amazon S3

I have uploaded my images to Amazon S3. There are some featured images. In order to modify their path, I run the update scripts to change the path of wp_posts.guid. But the image still points to the old path.

How can I change the featured image url so as to point to the Amazon S3 path?

Read More

Thanks

Related posts

2 comments

  1. You can hook into the output and modify the URL there.

    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 5 );
    
    function my_post_image_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
    
      $upload_dir = wp_upload_dir();
      $base_url = $upload_dir['baseurl'];
    
      // Change the default upload directory to AWS Bucket link
      $AWSBucket = 'http://s3.amazonaws.com/bucket';
      $html = str_replace($base_url, $AWSBucket, $html);
    
      return $html;
    }
    

    Output the image

    echo get_the_post_thumbnail ();
    

    Reference:

  2. Then you have to point the uploads folder to the same location. You can do it by making the below changes in the wp-config.php file

    Open up your wp-config.php file, located at the root of your WordPress installation, and add the following code:

    define('UPLOADS', 'http://amazon_url/uploads'); //Replace the url here with folder in Amazon
    

    The codex specifies that it should be added before the line that says require_once(ABSPATH.’wp-settings.php’);.

    Make sure the uploads folder is writable.

Comments are closed.