How can I get username into shortcode?

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 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 ?

  • Answer:

    In php, single quoted strings don't support variable interpolation. Change from single quotes to double quotes. The double quotes inside your string will need to be escaped. Change: <?php echo do_shortcode('[education="$username"]'); ?> to <?php echo do_shortcode("[education=\"$username\"]"); ?>

iberx at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

You are using single quote .. Use double quote and that should work. <?php echo do_shortcode("[education=". $username. "]"); ?>

Scalable

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.