WordPress.org

Ready to get started?Download WordPress

Forums

php in pages does not accept variables from outside the post (3 posts)

  1. sotiriskalathas
    Member
    Posted 2 years ago #

    Hello everyone,
    I use the php-exec plugin to run php inside pages and posts.

    I have some code inside my custom theme in header.php

    <?php
    ...
    ...
    $flag = 1;
    ?>

    Inside a page, using the HTML editor, I insert something like this:

    <?php if ($flag == 1){
    echo 'It works';
    }
    else{
    echo 'No, it does not';
    }
    ?>

    After I save my page and go to the site to see the results, it reads "No, it does not", which is wrong because $flag = 1 in the header!

    That means that the php code inside the post can't interact with the php code outside the post, in this example, in the header.php!

    Any ideas? I tried global $flag; in the header.php but still no luck.

    Thanks in advance!

  2. stvwlf
    Member
    Posted 2 years ago #

    try this

    <?php
    global $flag;
    if ($flag == 1){
    echo 'It works';
    }
    else{
    echo 'No, it does not';
    }
    ?>
  3. sotiriskalathas
    Member
    Posted 2 years ago #

    I've tried that and I'm afraid it doesn't work either...

Topic Closed

This topic has been closed to new replies.

About this Topic