0

I'm tryng to make my shortcode multilanguage but this code is not working:

add_shortcode('periodo_affitti', 'translate_rent');

function translate_rent()
{
    global $post;

    $lang = substr(get_locale(), 0, 2);

    if ('it' != $lang)
    {
        $period_lang = get_the_author_meta('periodo_affitti_$lang', $post->post_author);
        
        if (!empty($period_lang)) {
            return $period_lang;
        } else {
            return $period_lang;
        }
        
    } else {
        return $period_lang;
    }

} 
2
  • use " instead of ' to evaluate variable in string "periodo_affitti_$lang". php.net/manual/en/…
    – mmm
    Commented Aug 11 at 12:43
  • ok, it works! I just needed to create another variable for the italian version, because it's not "periodo _affitti_it", but just "periodo_affitti" Commented Aug 11 at 13:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.