Hide Magento custom attribute titles or data, when value is null

Posted on July 3, 2013 · Posted in Magento Tips & Tricks

If you have some custom attributes and you are displaying them on your product view page, you need to make sure, it doesn’t show a blank one, if you dont have anything entered for those custom fields in the backend.

For that, you need to place a complex PHP conditional code, which checks if there is data, then it shows and if there is no data, it doesnt show them up.
Here is the code snippet for one of my attribute.

< ?php if($_product->getCompatLink() != '') { ?>
  <div class="Compatable">
          <span><a href="<?php echo $_product->getCompatLink(); ?>" target="_blank">Compatable Products</a></span>
  < ?php  } ?>

NOTE : Here my attribute code CompatLink . So you need to change it as per your attribute name.