• Wondering how it might be possible to use a variable inside of a shortcode.
    I have a function that returns the current category number to a variable ($mycatid) and I would like to “pass” this number into the shortcode of a plugin I have installed “AZINDEX” in place of the “1” shown below. (somehow substitute $mycatid for the number)

    My PHP is pretty limited but I understand that the shortcode is seen as a string. Any ideas how I should approach this problem?

    ‘<?php $mycatid = getCurrentCatID();
    echo do_shortcode(‘[az-index id=”1″]’);?>’

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could try modifying what’s going on in the plugin file itself and leave the shortcode in the post unmodified.

    saythissaythat

    (@saythissaythat)

    Not sure if you figured this out long ago when you posted this, but I thought maybe the answer could help someone else out there.

    <?php $mycatid = getCurrentCatID();
    echo do_shortcode('[az-index id="'.$mycatid.'"]'); ?>

    Hey saythissaythat.

    Would that work for the post ID or other system variables as well? Slightly different syntax?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a variable inside a shortcode?’ is closed to new replies.