• This code is not working for me

    if ( ! is_user_logged_in() ) { 

    // Google Analytics Script Goes here

    }

    I have my google script in the header at the bottom of the page. First I saw the code in my public page, then I added <?php and ?> but I brok the site, maybe the php tags should stay before

    </header><!-- #masthead -->

    ?

    • This topic was modified 5 days, 20 hours ago by sacconi.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Google scripts belong in the <head> section, not the page’s header. Thus your theme’s header.php template. Assuming where you want the Google code to go in the template is already HTML code and not PHP, you’d implement the PHP logic like this:

    <?php if ( ! is_user_logged_in() ): ?>
       <script>
          // actual Google script goes here
       </script>
    <?php endif; ?>

    You could instead filter out data coming from your IP address in your Analytics account.

    Thread Starter sacconi

    (@sacconi)

    this is my header.php, I have to put the code into the head section top of the page? https://pastebin.com/Ek63Wspe

    Please check your code regarding this hint:

    Google scripts belong in the <head> section

    Thread Starter sacconi

    (@sacconi)

    ok, I put the code in header.php just before the tag

    </head>
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.