Support

Account

Home Forums Front-end Issues Qtranslate shorttags in field labels

Solved

Qtranslate shorttags in field labels

  • Hi All

    I use ACF frontend posting in a multylanguage site with qtranslate.

    I’m trying to get qtranslate shorttags to work in the labels of each custom field.

    ex:
    <!--:en-->Name<!--:--><!--:es-->Nombre<!--:-->

    For now I have accomplished this by changing line 793 of acf.php

    from

    echo '<label for="' . $field['id'] . '">' . $field['label'] . $required_label . '</label>';

    to
    echo '<label for="' . $field['id'] . '">' . apply_filters('the_title',$field['label']) . $required_label . '</label>';

    This will get the job done, but it’s very ugly and the code will be removed if the plugin is updated.

    Can i do this in a better way, with a hook or filter maybe ?

    Thanks.
    —-

    ACF Rules 🙂

  • Hi @harryhum

    Yes, you can use the acf/load_field filter. Docs available on the resources page.

    Thanks
    E

  • Hi @Elliot

    Thanks for your reply worked great.
    Here is the code I used for anyone that may need it. This will get the qtranslate tags working in the field labels and field instructions of a front-end form.

    function my_acf_load_field( $field )
    {
        if(!is_admin()){
            $field['label']  =  apply_filters('the_title', $field['label']);
            $field['instructions']   =  apply_filters('the_title', $field['instructions']);
        }
        return $field;
    }
    add_filter('acf/load_field', 'my_acf_load_field');

    I used is_admin()==false to make sure this only applies to the front-end forms. When used across the whole plug-in, the apply_filters functions seems to be called when acf prints the name of the field label in the wp-admin pages. Making the qtranslate tags invisible the first time you save the form and removing them completely if you save again.

    With is_admin() the translations will be visible in the admin pages while editing forms but this is not an issue in my case.

    Thanks again 🙂

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

The topic ‘Qtranslate shorttags in field labels’ is closed to new replies.