You’re not opening and closing the if
statement correctly, so the div is always being output. While you can use if
statements without the opening and closing parts like this if there’s only one line of code, that doesn’t work if the PHP tags are closed for HTML.
So you need to have this:
<?php if ( category_description() ) : ?>
<div class="myproductdescription"><?php echo category_description(); ?></div>
<?php endif; ?>
Or
<?php if ( category_description() ) { ?>
<div class="myproductdescription"><?php echo category_description(); ?></div>
<?php } ?>
I prefer the more verbose style when mixed in with HTML, but either one is fine.
Generally you should always avoid using the if
statement without opening and closing brackets, even if you’ve only got one line of code in the condition. It makes your code less clear and can cause serious issues if code that is supposed to be in the condition is added on a new line without adding the brackets. A major vulnerability in iOS was caused by this mistake in 2014.