Tagged: code
-
AuthorPosts
-
March 23, 2022 at 6:01 pm #1345728
I like to use Clicky Analytics on my Enfold sites, and therefore I have to add this code to all my pages:”
<script type=”text/javascript”>
var clicky_custom = clicky_custom || {};
clicky_custom.timeout = 30; // 30 minutes = 0.5 hours
</script>
<script async src=”//static.getclicky.com/000000000.js”></script>I don’t want to use a plugin for this, because the available plugins are all not well maintained in my idea.
I use a Child Theme and could be adding the footer.php file to my Child Theme and add to code in there, but I don’t like that either because the possible risk with Enfold updates.
Is there any other option to add the code above to my website pages, for example with my functions.php file in my Child Theme?
If yes… how..?Thanks for the help :)
AlwinMarch 23, 2022 at 7:12 pm #1345746Hey Alwin,
Please try this in your functions.php file:
function alwin_clicky_analytics_footer(){ ?> YOUR SCRIPT GOES HERE <?php } add_action('wp_footer', 'alwin_clicky_analytics_footer');
Best regards,
RikardMarch 25, 2022 at 9:00 pm #1346087Hello Rikard,
That code causes a critical site error.
However, i have found a better plugin now to ad the Clicky code, so for now i will use that!
Thank you,
AlwinMarch 26, 2022 at 2:54 pm #1346120The plugin doesn’t work well anyway, so I’d still like to add the Clicky code to my functions.php file.
As mentioned above, the above code led to a critical website error.
Do you have any other code I can try, and then maybe have the code placed not in the footer but in the header?
March 26, 2022 at 6:27 pm #1346136Hi,
We can’t help you out if we can’t access your site, please post login details in private.
Best regards,
RikardMarch 26, 2022 at 9:36 pm #1346154Hello Rikard,
I thought to be smart and put this Clicky code in the Enfold settings/Google Services/Google Analytics Tracking Code field:
<script async src=”//static.getclicky.com/101348066.js”></script>
However, that does not seem to work, the Clicky code is not added to my website, I can’t find it in the source code either.
So this Google Analytics field only really works with GA code?
(in the Ptivate Content my login credentials)
March 26, 2022 at 10:12 pm #1346158Hi,
Thanks for the login, but your theme editor option seems to be disabled, please enable it
or try adding this code to your child theme functions.php, I tested this on my test site without any issuesfunction alwin_clicky_analytics_footer(){ ?> <script src="//static.getclicky.com/101348066.js"></script> <?php } add_action('wp_footer', 'alwin_clicky_analytics_footer');
Typically if you get a critical site error when adding code to the functions.php it is because the quotes have changed into curly quotes from copying the code from an email and not from the forum.
Best regards,
MikeMarch 27, 2022 at 2:18 pm #1346209Hello Mike,
You say “the quotes have changed into curly quotes from copying the code from an email and not from the forum” and that was the issue!
I have copied the code directly from the forum and now it seems to be working fine!One related question: the functions.php file is included in the Child Theme by deafult and is initially an empty file. Isn’t it then the case that the functions.php file in the Child Theme overwrites the functions.php file in the parent theme, which seems to be strange because the functions.php in the Child Theme is empty by deafult?
Or does a functions.php file in a Child Theme work differently than, for example, a footer.php file in a Child Theme, which always overrides footer.php in a parent theme?
Thank you very much for your help!
March 27, 2022 at 3:20 pm #1346211Hi,
Glad to hear this helped, the functions.php file in a Child Theme appends the parent theme functions.php which is way you can not use a filter, action, or function with the exact same name as in the parent theme functions.php or functions-enfold.php
The header.php and footer.php or any other file overwrites the parent theme file.
If you can avoid using a child theme header.php or footer.php it may be a good idea, since the last few times that we updated those files it caused errors with client sites that they were not expecting. We don’t update these files often and it is always noted in the changelog, but it often catches people off guard.
Most of the time the changes can be made in the child theme functions.phpHopefully this helps, shall we close this then?
Best regards,
MikeMarch 27, 2022 at 7:36 pm #1346225Thank you very much Mike :)
One last question: the code is now in the footer but is it also possible to use code that adds the code in the header?
Alwin
March 27, 2022 at 8:00 pm #1346227Hi,
You can change the add_action to wp_head like this:add_action('wp_head', 'alwin_clicky_analytics_footer');
Best regards,
MikeMarch 28, 2022 at 3:41 pm #1346317Okay, so I have to change
add_action(‘wp_footer’, ‘alwin_clicky_analytics_footer’);in this
add_action(‘wp_head’, ‘alwin_clicky_analytics_footer’);and not in this?
add_action(‘wp_head’, ‘alwin_clicky_analytics_head’);Thanks :)
AlwinMarch 28, 2022 at 6:18 pm #1346332Hi Alwin,
wp-footer or wp-head, is a location, that is the only thing you need to change.
alwin_clicky_analytics_footer is only a name, you can name your function to anything that you wish. Just try to keep it specific, it minimises the risk of it clashing with another function which could have the same name.
add_action('wp_footer', 'alwin_clicky_analytics_footer');
Best regards,
Rikard -
AuthorPosts
- You must be logged in to reply to this topic.