samedi 14 juillet 2018

Wordpress. How to use shortcode with if else statement

I have following code but it's displaying shortcode in text rather than showing results of shortcode.

$curr_user_id = get_current_user_id();
// the value is 0 if the user isn't logged-in
if ( $curr_user_id != 0 ) {
    // we know now the user is logged-in, so we can use his/her ID to get the user meta
    $um_value = get_user_meta( $curr_user_id, 'user_phone', true );
    // now we check if the value is correct
    if ( ! empty( $um_value ) && $um_value == 'French' ) {
        // if so we can output something
        echo '[ld_course_list course_category_name="french" col=4 progress_bar=true]';
    } else {
    // else the code, eg.
    echo '[ld_course_list course_category_name="english" col=4 progress_bar=true]';
}
}

Above code will result in text below rather than showing results of the shortcode

[ld_course_list course_category_name="english" col=4 progress_bar=true]

How do I change my code so it actually runs shortcode?

Thank you.

Aucun commentaire:

Enregistrer un commentaire