DarkCid DarkCid - 2 years ago 116
PHP Question

How to get a post thumbnail with the WP Offload S3 Wordpress plugin

for my posts in my WP website, I use this code to get the URL of the thumbnail :

$thumb_id = get_post_thumbnail_id($single->ID);
$thumb_url = get_guid($thumb_id);

I've installed the WP Offload S3 plugin, but my code returned the local file url and not the S3 url.

Can you help me ?

Answer Source

I finally find a way in searching in the database. I find a data in the postmeta table, "amazonS3_info", with all the infos I need to generate the file URL :

function get_s3_thumb($post_id){

    $thum_id = get_post_thumbnail_id($post_id);
    $meta = get_post_meta($thum_id, 'amazonS3_info');
        // The file exist in S3
        $meta = $meta[0];
        $url = ($_SERVER['HTTPS'] == 'on')?'https':'http';
        $url.= '://s3-';
        $url.= $meta['region'];
        $url.= '.amazonaws.com/';
        $url.= $meta['bucket'];
        $url.= '/';
        $url.= $meta['key'];
        // The file dosen't exist in S3
        $url = get_guid($thum_id);
        if($_SERVER['HTTPS'] == 'on'){
            $url = str_replace('http', 'https', $url);

    return $url;

I post my function if anyone need it someday.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download