Archived topic
Can't Update or input code on Header.php
7 replies · Started by Mamun on November 23, 2021
I am trying to add my analytic codes in the header.php but can't do it, when I hit update after input analytic code this message popped up ( Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.)
One more thing, currently my header.php look like this
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<link rel="profile" href="https://gmpg.org/xfn/11">
<?php wp_head(); ?>
</head>
Hi Mamun,
It's not supposed to modify the theme files directly.
Can you tell me what is the instruction of installing the analytic codes exactly?
I have Updated my Google analytic code via the SiteTool>Site>File Manager> Public_html but can't update anything from inside the WordPress,
facing this problem from yesterday after updating the theme, my license was expired, I renew my license yesterday & update the theme, after that facing this issue
I was trying to install analytic code as they instructed
instruction of installing the analytic codes, Copy and paste this code as the first item into the <HEAD>
As Ying mentioned, it's never good to modify the theme's core files. They will be erased during updates as well.
To add the analytic codes, you can use the wp_head hook with a hook element:
https://docs.generatepress.com/article/hooks-element-overview/
https://docs.generatepress.com/article/wp-head/
Reference: https://github.com/tomusborne/generatepress/blob/master/header.php#L17
My question is why this option isn't working? I can update this from the cpannel but why not from WordPress?
I'm not sure what you are referring to here?
My solution above should be the only option you need.
The theme itself cannot control the functionality of cpanel etc.
Hi Mamun,
you need to add Google Analytics via a plugin or enqueue in a child theme functions.php file. If you haven't created a child theme, then you need to use a plugin to add the analytics. Otherwise, whatever you add to the theme will be overwritten by an update.
If you get GeneratePress Premium plugin, then you can add that code via Hook element.
The GP theme is meant to be edited by hooks.