Modify featured image path to Amazon S3

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:

Leave a Comment