Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #359370

    Hi ENfold,

    I have received a request from our PPC specialist to add a code snippet to the site. Easier said than done.

    Although the code snippet he sent us is ready-to-go, just inserting the snippet in the .php code may be more invasive than we want to be. We might accomplish this via one of the WordPress plugins instead.

    Facts:

    – several help topics say to modify header.php, but one warns that this will be overwritten if you did not use a child theme
    – we did not use a child theme for this site
    – per Ismael at https://kriesi.at/support/topic/analytics-code-placed-outside/, modifying the header.php code directly leaves it open to deletion the first time we upgrade the theme, so he recommends inserting an add_action statement into the functions.php file
    – I am not sure at which line in the functions.php file that should go
    – there are WordPress plugins that can do this https://wordpress.org/plugins/tags/tag-manager
    – I installed the metronet tag manager to have a look, and it warns that a modification should be made to place the snippet at the right point on the page, likely requiring a header.php edit, which would be wiped out in a theme update, so we’re running in circles

    I appreciate the help.

    Thanks! -Alan

    #359430

    Hi slimmer1!

    Thank you for using Enfold.

    I’m not sure what code you’re trying to add but you can hook the snippet on the head tag with this:

    add_action('wp_head','ava_hook_script');
    
    function ava_hook_script() {
         $output = "SCRIPT HERE";
         echo $output;
    }

    You can add the code at the very bottom of functions.php file.

    Regards,
    Ismael

    #359804

    Hi Ismael,

    I will try the above, replacing “SCRIPT HERE” with our custom Google Analytics snippet at the end of our functions.php file, and I’ll let you know how this worked for us. The script looks like this.

    <script>
    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    …et cetera…
    …et cetera…
    ga(‘send’, ‘pageview’);
    </script>

    I’ll let you know how the site behaves after modifying and replacing functions.php.

    Thanks! -Alan

    #360142

    Hey Alan!

    Let us know how it goes, also as you are not using a child theme i’d recommend using a plugin like this to store custom functions separated from the theme files – https://wordpress.org/plugins/functionality/

    Cheers!
    Josue

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