Hide entire widget if no results returned
-
I am using a PHP widget to check for the existence of a particular custom field and display it if it exists. I’ll call the field “information”. I do not use a widget title in this case because most of the time the custom field doesn’t exist and I didn’t want an empty title box in my sidebar. My code is shown below and it works fine.
<? php $values = get_post_custom_values(“information”);
if ( !empty($values) ) {
echo ‘<h3 class=”widgettitle”>Information:</h3> ‘ . $values[0]. ‘ ‘;
}
?>The problem is if there is no “information” custom field to display,
I get an empty box. Not a huge problem, just esthetically displeasing.I am wondering is if there might be a way, say in functions, that I could keep the entire php widget from showing up if it has no value? Ideas?
- The topic ‘Hide entire widget if no results returned’ is closed to new replies.