WordPress.org

Ready to get started?Download WordPress

Forums

Add a variable inside a shortcode? (4 posts)

  1. hyperburst
    Member
    Posted 4 years ago #

    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"]');?>'

  2. iridiax
    Member
    Posted 4 years ago #

    You could try modifying what's going on in the plugin file itself and leave the shortcode in the post unmodified.

  3. saythissaythat
    Member
    Posted 4 years ago #

    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.'"]'); ?>
  4. jrack
    Member
    Posted 4 years ago #

    Hey saythissaythat.

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

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic