Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodrigo-brito/ba7f2c4253428bae9dcda1abaf5d99de to your computer and use it in GitHub Desktop.
Save rodrigo-brito/ba7f2c4253428bae9dcda1abaf5d99de to your computer and use it in GitHub Desktop.
RB External
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) {
if ( $meta_key === '_thumbnail_id' ) {
$url_thumbnail_external = get_post_meta( $post_id ,'thumbnail_external', true );
if( !empty($url_thumbnail_external) ){
return "ext-" . $post_id;
}
}
return $value;
}, 10, 4);
add_filter( 'wp_get_attachment_image_src', 'rb_external_attachment_image_src', 10, 4 );
function rb_external_attachment_image_src( $image, $attachment_id, $size, $icon ){
if(isset($attachment_id) && !empty($attachment_id) && substr($attachment_id, 0, 3) === "ext"){
$id = substr($attachment_id, 4);
$thumbnail = get_post_meta( $id ,'thumbnail_external', true );
return Array ( $thumbnail, 0, 0, false );
}
return $image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment