How can we get username into a shortcode

How can we use $usernamein a shorcode

<?php echo do_shortcode('[education="$username"]'); ?>

But it doesn’t work

Edit:

Web site is a wordpress site with user-pro plugin.

authors page slug as

domain.com/profile/username

domain.com/profile/john-doe

I added this code to userpro index.php to get username from slug .

function func_print_username($username) {
    global $query_string;
    if($query_string != 'pagename=profile') {
        $patterns = '/(w+)=(w+)&(w+)=/i';
        $username = preg_replace($patterns, '', $query_string);
    } else {
        global $current_user;
        $current_user = wp_get_current_user();
        $username = $current_user->user_login;
    }

    return trim($username);

    return "education= { trim$username[education] }";
}
add_shortcode('education', 'func_print_username');

I have a shortcode as [education="username"]. It works manually [education="john-doe"]

I want to get username into my shortcode on user profile page

<?php echo do_shortcode("[education="username"]"); ?>

But it’s not working. What am I missing ?


Source: shortcode

Leave a Reply