Support

Account

Home Forums General Issues Shortcode to include label and value

Helping

Shortcode to include label and value

  • Hi everyone.

    I am looking to find how to get a short code that will show the label first and then the value. Ideally I would like to be able to style the label and value differently. Currently there doesn’t seem to be any documentation on how to do this.

    So to be clear I have a Field called, Plant Name, so I would like a short code to display Plant Name: Apple Tree. So that if the field is empty neither the Label or the Value show on the outputed post.

    Any help would be amazing

  • Sorted this myself.

    For the record I have created a shortcode.php file and called it from functions.php

    It was quite easy once I understood. This is the type of code I used

    function cultivar_name() {
    if(get_field(‘cultivar’)){
    $field_name = “cultivar”;
    $field = get_field_object($field_name);
    echo ‘‘, $field[‘label’],’‘ . ‘: ‘ . ‘<div class=”headlinename”>’, $field[‘value’],'</div>’,'</br>’;}
    }
    add_shortcode( ‘cultivar’, ‘cultivar_name’ );

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

The topic ‘Shortcode to include label and value’ is closed to new replies.