Support » Plugin: Shortcode Exec PHP » [Plugin: Shortcode Exec PHP] Get variables (not push) via Shortcode

  • Resolved Sebastian


    Is there a possibility to get a variable I’ve stored in the php-plugin? Like [shortcode arg=”value”] …but vice-versa. For example: I have a shortcode-function called [example]
    and the following php-script:

    $variable1 = "text1";
    $variable2 = "text2";
    return $variable1 ." ". $variable2;

    No problem, if I call the [example]-Shortcode, it will write “text1 text2” – BUT I’d like to have only the first variable.

    The reason of my question is simple: I do use different shortcodes for those who are guests, and those whoe are loggedin. Most of the php-script is the same and I have many (!) php-scripts, so it’s better not to duplicate the whole scripts and styling them every time again. I hope you got my ugly english 😀


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor M66B


    I am not sure what you want, but you can pass arguments to a shortcode, take a look in the WordPress codex for how to. It is also possible to store things, take a look at the update_option function.

    Sorry, I’m not quite familiar with it and have problems to understand it. Hopefully you’ll get it now 😉 Let me do an example: In the article I write e.g. (I know, it’s the wrong code):

    [shortcode getthisvariableandpublish—>>>variable1]

    In the shortcode exec php-plugin I’ve added the shortcode called shortcode with the variable $variable1. There are other variables, so I cannot return them. I want just ONE variable… the $variable1.

    The article should now proceed the text, which is included in the $variable1.

    Plugin Contributor M66B


    I think you want something like this:

    extract(shortcode_atts(array('text' => 'default'), $atts));
    if ($text == 'a') return 'Text A';
    else return 'Text B';

    [shortcode text="a"] -> ‘Text A’

    [shortcode text="b"] -> ‘Text B’

    Wonderful! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Shortcode Exec PHP] Get variables (not push) via Shortcode’ is closed to new replies.