What's the easiest way to insert a global site tag on a WordPress site?
 by Kristi Hagen

What's the easiest way to insert a global site tag on a WordPress site?

  • I'm being asked to insert a global site tag {gtag('config', 'AW-xxxxxxxxxxxx');} into the Thank You page of a client's site by the Google Digital Account Exec. This is a WordPress site built by others. I attempted to insert this into the functions.php file (that seems easiest), and got an error when doing so:

    Your PHP code changes were rolled back due 
    to an error on line 45 of file
    wp-content/themes/ipropads/functions.php.
    Please fix and try saving again.
    
    Uncaught Error: Call to undefined function gtag() 
    in wp-content/themes/ipropads/functions.php:45
    Stack trace:
    #0 wp-settings.php(426): include()
    #1 wp-config.php(95): require_once('/users/ipropads...')
    #2 wp-load.php(37): require_once('/users/ipropads...')
    #3 wp-admin/admin.php(31): require_once('/users/ipropads...')
    #4 wp-admin/theme-editor.php(10): require_once('/users/ipropads...')
    #5 {main}
    thrown
    

    Can you give me a hint on the easiest way to accomplish this?

Answer:

The easiest way to do this is to add the SOGO Header Footer plugin - https://wordpress.org/plugins/oh-add-script-header-footer/

This plugin lets you add custom code into an individual page on a WordPress site. It's great for adding page specific items like Structured Data markup, Javascript, or tracking codes - like you're wanting to. To use it just:

  • Login to the backend of the WordPress site and navigate to the Plugins > Add New page.
  • Use the Add New button at the top of the page to search out and add the SOGO plugin.
  • Once activated, you'll find two new SOGO editing sections (header and footer) at the bottom of every page WordPress editor interface.
  • Paste the tracking code in the SOGO header field of the Thank You page, hit Update on the entire page and you're good to go.SEN article end
...

TO READ THE FULL ARTICLE

SearchEngineNews.com Logo

Continue reading your article with a $1 Trial SEN Membership

VIEW MEMBERSHIP OPTIONS