Support » Plugin: PHP code snippets (Insert PHP) » Passing variables through snippets (help)

  • Resolved grolli


    Hello! Can someone please help me on this?

    I got very basic skills on PHP and i’m wanting to adapt to the new version of the plugin, which I think it’s great and much more dynamic.

    So with the old version I used to had a single page using the plugin, displaying long codes through the [insert_php] tags. Now with this new version I wanted to break the code in two parts, pretty much like this:

    CODE 1 = snippet that will run in everypage. it gets a few parameters, like the date
    $todayD = date("d");

    it can always procces these parameters and generate new variables.
    $example = $todayD * 3;

    CODE 2 = snippet that will run only via shortcodes. it will only show these results.
    echo 'The number is ' . $example;

    My problem is that i can’t seem to pass these variables through the snippets. Is there any way to do this? Sorry if this question is too dumb.

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Plugin Author webcraftic



    I’m sorry, I needed to update other plugins. Now I’m back to you and can help you.

    Snippet, which should be run everypage:

    global $wbcr_example;
    $todayD = date("d");
    $wbcr_example = $todayD * 3;

    Be sure to use prefixes or make unique variable names that you use this variable globally. I for example added to your variable a prefix wbcr_

    Now $wbcr_example var will be available on all pages.

    Snippet, which is called with a shortcode

    global $wbcr_example;
    echo 'The number is ' . $wbcr_example;

    Best regards, Alex

    • This reply was modified 2 months ago by  webcraftic.
    • This reply was modified 2 months ago by  webcraftic.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.