I’m guessing that if there is no image in a recipes gallery it returns the php warning!
Plugin Author
XjSv
(@xjsv)
Hello @bihush, There is a check in the code to check if the gallery is empty and if so it does not attempt to load any files.
I also just did a test right now to see if a recipe with no gallery images causes a error but I did not see anything.
Could you link the recipe in question so I can take a look? Maybe there is a clue as to whats going on.
There is no specific recipe! That php warning is in my error-log
I did this tweak in my local, it seems like solved the issue but do you think it’s a good approach? I have large amount of recipes I wanna make sure, before going online with this fix
if ( isset($gallery_items) && !empty($gallery_items) ):
foreach( $gallery_items as $item ):
$image_src = wp_get_attachment_image_src( $item, [900, 900] );
$image_title = get_the_title( $item );
if ( is_array($image_src) && isset($image_src[0]) ) {
$gallery_html .= '<a href="' . esc_url( $image_src[0] ) . '" data-alt="'.esc_attr( $image_title ).'" data-caption="'.esc_attr( $image_title ).'">
<img alt="'.esc_attr( $image_title ).'" src="' . wp_get_attachment_image_url( $item, 'thumbnail' ) . '" />
</a>';
}
endforeach;
endif;
Plugin Author
XjSv
(@xjsv)
Interesting, because “!empty($gallery_items)” should have not allowed the loop if the array is empty. But I can see how it could possibly lead to this.
Thank you for that, I will add this to the source code so that when the next update comes out you don’t loose any functionality.