Skip to content

Instantly share code, notes, and snippets.

@aliaghdam
Last active May 31, 2017 14:47
Show Gist options
  • Save aliaghdam/8ef5f97413f92485968c187ce838fef5 to your computer and use it in GitHub Desktop.
Save aliaghdam/8ef5f97413f92485968c187ce838fef5 to your computer and use it in GitHub Desktop.
"Publisher" compatibility with "Featured Image From URL"
<?php
add_filter( 'wp_get_attachment_image_src', 'fifu_replace_attachment_image_src', 10, 2 );
if ( ! function_exists( 'fifu_replace_attachment_image_src' ) ) {
/**
* Replaced attachment src with external thumbnail URL
*
* @hooked wp_get_attachment_image_src
*
* @param $image
* @param $attachment_id
*
* @return array
*/
function fifu_replace_attachment_image_src( $image, $attachment_id ) {
if ( $attachment_id == get_post_thumbnail_id( get_the_ID() ) ) {
$src = get_post_meta( get_the_ID(), 'fifu_image_url', TRUE );
if ( $src ) {
return array(
$src,
0,
0,
FALSE
);
}
}
return $image;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment