mercredi 6 juillet 2016

Conditional display of custom meta field in genesis framework

I am trying to make my webpage display data in a custom meta field only if there is data to display. This is what I have right now.

<?php
    add_action( 'genesis_before_entry_content', 'state_meta' );
    function state_meta() {
    echo '<br /><strong>State</strong>: ';
    genesis_custom_field('state');
    }
?>

I tried the following code, but the echo statement fails: the label 'State' doesn't display but the field data of 'genesis_custom_field('state')' shows up.

<?php
add_action( 'genesis_before_entry_content', 'state_meta' );
function state_meta() {
    if(genesis_custom_field('state'))
    {
        echo '<br /><strong>State</strong>: ';
        genesis_custom_field('state');
    }
}
?>

Aucun commentaire:

Enregistrer un commentaire