Offload Media Links
-
Howdy, when using a media offloader to Amazon s3, the image tags load images but their links go to a 404. This is because the link goes to WP’s native media directory instead of the offloaded images on Amazon s3. I’ve tried overriding with functions.php with no luck with the following:
add_filter( 'pre_option_upload_url_path', function( $upload_url_path ) {
return 'https://bucket.s3.us-west-1.amazonaws.com';
});I have successfully gotten links to work when modifying wp-content/plugins/meow-gallery/classes/core.php at line 409 within function get_gallery_options adding:
wp_upload_dir['baseurl'] = 'https://bucket.s3.us-west-1.amazonaws.com';Along with modifying line 867 with:
$wpUploadDir['baseurl'] = 'https://bucket.s3.us-west-1.amazonaws.com';Modifying the plugin core of course isn’t ideal. I tried using the attribute override but it seems $atts[‘link’] isn’t supported. Tried with simply image.jpg which doesn’t override:
add_filter( 'shortcode_atts_gallery', function( $result, $defaults, $atts ) {
if ( !empty( $atts['link'] ) ) {
$image_link = $atts['link'];
$new_link = str_replace("https://site.com/wp-content/uploads","https://bucket.s3.us-west-1.amazonaws.com",$image_link);
$atts['link'] = $new_link;
}
return $atts;
}, 10, 3 );
You must be logged in to reply to this topic.