Support

Account

Home Forums General Issues Where to add those snippet? Display a field’s label and hiding empty fields

Helping

Where to add those snippet? Display a field’s label and hiding empty fields

  • Hello!
    I’m beginner with code…
    I have a template create with elementor pro to display dinamic custom fields.
    I need to display before the dinamic content their label, for example:

    Colour: red

    Now it only appears red, I would like their label before, in this case display “Colour:”

    I found that code but is it what I need for?

    <?php
    $field = get_field_object('my_field');
    ?>
    <p><?php echo $field['label']; ?>: <?php echo $field['value']; ?></p>

    If it’s OK, where I have to place that code?
    Thank you in advanced!

    I have the same doubt with another code, if colour is empty, I would loke to hiding that field (this one and all I have).

    With this code is possible? And where to place it?

    <?php 
    
    $fields = get_field_objects();
    
    <?php if( $fields ): ?>
        <ul>
        <?php foreach( $fields as $field ): ?>
    
            <?php if( $field['value'] ): ?>
                <li><?php echo $field['label']; ?>: <?php echo $field['value']; ?></li>
            <?php endif; ?>
    
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

    THANK YOU SO MUCH FOR YOUR HELP

  • The code you are finding would be added to the page template code and can’t be used in elementor. Adding code to elementor is not a simple process and I can’t really help you much there. You should do a search on adding code to elementor. The Code Snippets plugin is may help you. You may need to either build a shortcode or some other way. There are likely other ways to do this if you search.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.