Support

Account

Home Forums General Issues Converting Form "Image Labels" back to text labels for front end content

Unread

Converting Form "Image Labels" back to text labels for front end content

  • So I successfully used my_acf_load_field to replace labels with images on my front-end form (see below). Cool. But now – for the front-end content to come from that form – I need to display the selected label value instead of the pretty pictures I had on the form.

    I thought something like this would be possible using the same snippet ACF gives for returning the categories instead of the IDs, but I wasn’t able to get it to work. That might be because that code only works on taxonomies/tags.

    Here is my original code to convert the labels to images

    function my_acf_load_field( $field ) {
    
        $field['choices'] = array(
            'Learn' => '<img src="http://example.com.image1.svg" alt="image" width="150" height="150" />',
            'Pet' => '<img src="http://example.com.image2.svg" alt="image" width="150" height="150"  />'
            
        );
    
        return $field;
    }
    add_filter('acf/load_field/name=field_name', 'my_acf_load_field');

    …Can I reverse it back for the front end content? Thanks

Viewing 1 post (of 1 total)

The topic ‘Converting Form "Image Labels" back to text labels for front end content’ is closed to new replies.