Alternate text if shortcode returns no data

I’m using some plugins like beer list from Rescuethemes, and an event list, that use a shortcode to display a list of items. I put the shortcode into a Page, and it shows the data. If the shortcode evaluates to no data, like no beers in this category, or no upcoming events, I’d like to show alternate text, like “There are no upcoming events”.

What is the best way to accomplish this? Is this something I can do as a conditional in the Page itself? Am I better off just doing the check in the plugin itself and tweaking the return value? Does something like this belong in a Page Template?

1 Answer
1

You should do this in the shortcode/plugin itself. An easy way to do it may be something like this:

// if the shortcodes empty:
if ( empty( $shortcode_content ) ) {
    // set a default nothing found message
    $shortcode_content="Sorry! Nothing found";
}
return $shortcode_content;

Leave a Comment