Support » Developing with WordPress » Using variable in shortcode

  • janwwebdesign

    (@janwwebdesign)


    It is for a wheather site, a Meteobridge uploads an php file with some $variable like: temperature, moisture, windspeed. This file with the $variable is included in page.php in WordPress. Now I will shortcode the data in the wordpress pages.

    I want to use an $variable who is outside the function. In the shortcode function.

    This is what i will do:

    function shortcodevariable( $atts ){
        return 'echo $variable';
    }
    add_shortcode('variable', 'shortcodevariable');

    I think we need an array but I dont now how, can somebody help?
    When I echo the $variable in page.php then I see the value of the $variable, so that is working.

    Now with the use of a shortcode!

    Thank you very much for the answer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    This [uploaded] file with the $variable is included in page.php

    I don’t know what the source of the uploaded PHP file is, but this sounds like a horribly insecure scheme. Any arbitrary code could be included in this file and it will be executed with full PHP server privileges. There couldn’t be an easier way to inject malicious code.

    Data should be transmitted in a format not prone to malicious code injection, like JSON or XML.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using variable in shortcode’ is closed to new replies.