Hello
I'm trying to create the option for an alternative featured image.
This basically works fine with this filter as described here
https://wordpress.stackexchange.com/questions/299844/possible-to-swap-in-a-placeholder-image-globally-for-the-post-thumbnail-url-if-o
But it only works when I hardcode the URL. As soon I want it to fetch from single image field, I got plenty of errors. Although only fetching the url by it self is working fine.
See example in this short video (including audio)
https://www.berrycast.com/conversations/86c539fb-e04e-57b5-91a1-6f38faddc18a
I spent already many hours without success and hope for a hint, why this is not working.
Thanks
François
Filtercode
function gof_image_src( $image, $attachment_id, $size, $icon ) {
if( ! is_single() ) { return $image; }
$opt = rwmb_meta( 'gop_base_bg_img_opt' );
if( $opt == 'show-global' ) {
$img_alt = rwmb_meta( 'gop_base_img', ['size' => 'full'] );
$img_alt_url = $img_alt['url'];
$image = [$img_alt_url];
//$image = ['https://dev-mf.local/wp-content/uploads/demo-po-tasha-jolley-jqSysL9rQHc-unsplash.jpg',];
}
return $image;
}
add_filter( 'wp_get_attachment_image_src', 'gof_image_src', 10, 4 );