I'm trying to set up a page with an image gallery where, if the alt field is empty, it'll display whatever is in the caption (at least one or the other will always have content). This is my current code, which is displaying nothing at all.
$image_all = wp_prepare_attachment_for_js($item->ID);
if (empty($image_all['alt'])) {
echo $image_all['caption'];
} else {
echo $image_all['alt'];
}
If I just put in echo $image_all['alt'];
(or 'caption'
) it displays just fine. But using the if statement results in nothing displaying at all.
What am I doing wrong?