• Hi guys,

    I added a function to the functions.php. This function will set a variable, let’s call it $test. I need to access this variable within the loop. How would I do this? I obviously can’t create a global variable in a function, can I?

    I am using a plugin to write php code in posts and need this variable within the loop.

    Anyone has experience with this and would help me?

    Thanks,
    sOliver

Viewing 1 replies (of 1 total)
  • Haven’t programmed for a while, but was easier than expected.

    If anyone wants to know how to do it:
    functions.php
    function my_function() {
    if (whatever){
    return “test”;
    }
    }

    this goes into your post:
    <?php
    if (function_exists(‘my_function’)){
    $var1 = my_function();
    if ($var1 == “test”){
    DO WHATEVER
    }
    }
    ?>

    I hope this will help someone else. You can do some pretty amazing things with the functions.php

    Keep rocking guys

Viewing 1 replies (of 1 total)
  • The topic ‘How-to pass a variable from functions.php to post?’ is closed to new replies.