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.

I have a function in my functions file where i output Google Analytics code.

    function mytheme_trackingcode(){
    $mytheme_option = mytheme_get_global_options();
    $tracking_code = $mytheme_option['tracking_code_head'];
    if($tracking_code){
        echo '$tracking_code';
    }
}
add_action('wp_head', 'mytheme_trackingcode');

The problem is that the output comes right after the tag. I'm not sure what the problem is? wp_head is placed last in head-section.

share|improve this question
    
Can you post the portion of the code that does wp_head()? –  m0r7if3r Mar 18 '12 at 17:15
    
i'm not sure i understand your question. wp_head is a core WordPress action. –  andeersg Mar 18 '12 at 17:20
    
Yes, a core action executed by wp_head(), which must be called at the correct time by your theme...typically in header.php. –  m0r7if3r Mar 18 '12 at 17:23

1 Answer 1

up vote 1 down vote accepted

'$tracking_code' ist just a string. It closes <head> automatically. So, no, it doesn’t come after the head, you just failed to use source view. Firebug and similar tools show just the rendered DOM, that’s not good enough.

Fix: echo $tracking_code;.

share|improve this answer
    
I removed the ' and tried again, but i discovered a new problem, WordPress strips the <script> tags. –  andeersg Mar 18 '12 at 17:35
    
@andeersg No, it doesn’t. I’m 100% sure. –  toscho Mar 18 '12 at 18:05
    
I checked again and tried with the "esc_js" function when i save the code. Then the script tags was included, but the code gets " around the code and it is outputed after body tag. –  andeersg Mar 18 '12 at 18:10
    
Then your save function is wrong, not the output. –  toscho Mar 18 '12 at 18:14
    
I'm googling alot now, but can anyone point me in the direction of the function recommended for saving inline-javascript and outputing it? –  andeersg Mar 18 '12 at 18:17

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.