Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Situation:

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:

    add_filter('the_content','simple_img_tag_search');
    function simple_img_tag_search($content){
    if(is_single()){
        $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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.