1

I am trying to define a variable for a plugin using a php variable inside of a shortcode in Wordpress.

What I want to use is this:

[wpdatachart id=16 var1="<?php echo um_profile_id(); ?>"]

Obviously this won't work, but what is the proper way of writing this?

1
  • Why don't you pull the var inside the shortcode function? You could replicate um_profile_id(): hookr.io/functions/um_profile_id Commented May 9, 2017 at 23:59

4 Answers 4

1

This depends on where you want to add the shortcode.

If you want to add shortcode through some PHP Code than solution provided by "shr3jn" is perfect.

However, if you want to add this in some page than you need to dynamically replace value while wrinting add_shortcode command, using $atts parameter. Refer documentation here

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

<?php echo do_shortcode('[wpdatachart id=16 var1="'. um_profile_id().'"]'); ?>

Comments

0

You can echo inside shortcode using do_shortcode function of wordpress.

<?php
    echo do_shortcode( '[shrtcd]' . function() . '[/shrtcd]' );
?>

1 Comment

<?php echo do_shortcode( '[shortcode]' . function() . '[/shortcode]' ); ?>
0
<?php echo do_shortcode('[shortcode]'); ?>

Replace the shortcode in square bracket with your shortcode.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.