0

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);
    }}
2
  • 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. :) Commented Aug 7, 2012 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
    Commented Aug 7, 2012 at 15:30

1 Answer 1

2

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;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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