Google Analytics

Home Forums Receptar Google Analytics

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19051

    topkhoj
    Participant

    Google Analytics

    Resolved

    where to add Google Analytics and other code in header.php file because the file doesn’t allow to add any code before wp_head();. Kindly suggest me.
    I’ve also created a child theme and I want to add some custom scripts such as Google Analytics and Google Adsense code in header.php in the child theme, how can I do it?

    #19053

    Oliver Juhas
    Keymaster

    Hi topkhoj,

    Please understand that this is a new issue and you should log a new ticket for it – please read terms of service.

    For inserting a Google Analytics code you should use a plugin.

    If you want to add it using a code in your child theme‘s functions.php file, you can perfectly use the wp_head hook.

    function child_theme_google_analytics() {
      echo 'YOUR CODE HERE';
    }
    add_action( 'wp_head', 'child_theme_google_analytics', 5 );

    Not sure why you need to add the code before wp_head(), but if you really want to do that, simply set a negative action hook priority in above code, or use a different hook, such as wmhook_head_top or wmhook_head_bottom instead of wp_head.

    The theme is full of action hooks so you can add your custom code whereever you want (you can hook your code onto any wmhook_ actions in the header).

    Best regards,

    Oliver Juhas
    WebMan Design

    • This reply was modified 3 months, 1 week ago by  Oliver Juhas. Reason: Fixing typos
    #19055

    topkhoj
    Participant

    Getting T_STRING Error

    #19058

    Oliver Juhas
    Keymaster

    Hi topkhoj,

    You can not use single quotes (') in your code when you use those in the echo already. You can fix this issue by wrapping your code in double quotes (") or change the quotes in your code to double quotes instead.

    Please understand that you are responsible for your custom code, custom theme modifications. I can only provide tips for those – please read terms of service.
    If you are not familiar with WordPress development, I suggest hiring someone to help. Thank you for understanding.

    Best regards,

    Oliver Juhas
    WebMan Design

    #19063

    topkhoj
    Participant

    OK.
    Thank You, Oliver.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.