Home Forums Front-end Issues Displaying Field Labels Reply To: Displaying Field Labels

  • Basically, you’d need to create your own shortcode

    It’s described here in the WP Codex:

    Here is the function from ACF

    function acf_shortcode( $atts )
        // extract attributs
        extract( shortcode_atts( array(
            'field'			=> '',
            'post_id'		=> false,
            'format_value'	=> true
        ), $atts ) );
        // get value and return it
        $value = get_field( $field, $post_id, $format_value );
        if( is_array($value) )
            $value = @implode( ', ', $value );
        return $value;
    add_shortcode( 'acf', 'acf_shortcode' );

    You’d need to decide what additional things you’d want to be able to do and set up the attributes. Then you’d need to research the ACF functions and filters to that will allow you to get other information about a field and display it.

    Honestly, not that complex. For example you can get all the other field data by calling get_field_object(), you can read more about this function here:

    The difficult part is not getting the data but formatting it. It’s easy to get a value and just output it, but if you’re going to get the label and the value or any additional information, for example, what if there is no value, do you output the default? If there is not value to you still output the label? You’re going to have to provide ways for developers to format what the field will look like, as well as what the default is.

    Hope this helps.