I have a working shortcode, ie like this:

[shortcode_name search="" show="url, color, size"]

In this shortcode if I insert for example an email inside search (search="[email protected]") it displays all entries from that e-mail. If I don't write anything, it displays all entries from all e-mails.

I would like to insert a variable like search="'.$user_email.'" to display all entries of that logged user.

How can I use that variable?

I tried also with a shortcode that generates the e-mail, but how to use a shortcode inside another shortcode? I tried [shortcode_name search="[user_email_shortcode]" show="url, color, size"] but of course it doesn't work.

  • Is [shortcode_name] created by you? If not, are you able to create your own shortcodes? (You could just create a [shortcode_name_loggedIn] that basically returns the other shortcode with the email pre-filled)
    – kero
    Feb 5, 2021 at 15:18
  • You can't put shortcodes inside the attributes of other shortcodes, it will break the parsing and neither shortcode will work, regardless of what code you run when the shortcode is processed ( because it never finds the shortcode correctly to process it ). This approach is a dead end, you will need to find alternative solutions, e.g. a new shortcode that combines the two in PHP code
    – Tom J Nowell
    Feb 5, 2021 at 15:45

1 Answer 1


apparently I found the solution (thanks to amatorpl), if anyone needs it:

function show_history() {

$user = wp_get_current_user();
$user_email = $user->user_email;

$show_history = '[shortcode_name search="'.$user_email.'" show="url, color, size"]';
$history =  do_shortcode($show_history);

return $history;

add_shortcode('show_history', 'show_history'); 

Thanks for the try

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.