WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Is header.php file where is code: if(is_single()){ global $my_global_var; $my_global_var == true; }

Is functions.php file where is code: global $my_global_var; if($my_global_var == true) { echo "OK"; }

But this is not working, what im doing wrong?

In sidebar all is fine.

Fixed 0.2: Must be:

    function simple_img_tag_search($content){
        $MYCODE = "<div>My code</div>";
        $paragraphs = explode( '</h2>', $content, 2 );
        $first_paragraph = $paragraphs[0];
        return str_replace($first_paragraph.'</h2>',$first_paragraph.'</h2>'.$MYCODE,$content);
share|improve this question
It's not working because functions.php is loaded before header.php. By the time your header file sets it's variable, functions.php has already been executed. You need to post your code -- including what you're trying to accomplish -- to get any more help that that. :) – chrisguitarguy Aug 7 '12 at 15:29
@Vital You already got 7 questions here on the site. Please take your time, go back and edit your question with the WYSIWYG editor. Thanks. – kaiser Aug 7 '12 at 15:30
up vote 2 down vote accepted

is_single() is a function returning a boolean value. You could simply use it for your conditional check rather than passing the global variable.

Other than that, your first line of code should be setting $my_global_var with a single equal sign, i.e.: $my_global_var = true;.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.