X: Theme Header (header.php) and Google Analytics

Hello team,

While tryying to install the Google Analytiics code on the header.php sections, I don’t what happened. Now the section is empty (I must have deleted something) and the website looks messed up (no footer, no header).

Please help.

Thanks.

Hello There,

Thanks for writing in! Cases like this, missing header, footer could only be triggered by a fatal error. There might be an error in the code that you have added. Could you please share the code in your next reply?

Regards.

It was Google Analytics code that II was trying to install. I deleted the header.php and a section of the footer and that;s what messed up the website.

I traced my way back and everything is back on. How do I install the Google analytics code?

Hi There,

You can insert google analytic code in the header via child theme function file.
Please add this php function to your child theme function.php file. it will add the code to header.

<?php
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>

// Paste your Google Analytics code from Step 4 here

<?php } ?>


Hope this helps!
Thanks.

Hello @basanta,

I installed the insert headers and footers plugin. That seems to have worked well.

Thank you.

You are most welcome!