Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #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 :)
    Alwin

    #1345746

    Hey 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,
    Rikard

    #1346087

    Hello 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,
    Alwin

    #1346120

    The 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?

    #1346136

    Hi,

    We can’t help you out if we can’t access your site, please post login details in private.

    Best regards,
    Rikard

    #1346154

    Hello 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)

    #1346158

    Hi,
    Thanks for the login, but your theme editor option seems to be disabled, please enable it
    2022-03-26_007.jpg
    or try adding this code to your child theme functions.php, I tested this on my test site without any issues

    
    function 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,
    Mike

    #1346209

    Hello 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!

    #1346211

    Hi,
    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.php

    Hopefully this helps, shall we close this then?

    Best regards,
    Mike

    #1346225

    Thank 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

    #1346227

    Hi,
    You can change the add_action to wp_head like this: add_action('wp_head', 'alwin_clicky_analytics_footer');

    Best regards,
    Mike

    #1346317

    Okay, 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 :)
    Alwin

    #1346332

    Hi 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

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.