skip to Main Content

WordPress Code Snippets


Adding Google Analytics to Your WordPress Theme

Learn how to integrate Google Analytics into your WordPress theme for tracking site performance.

function codebykp_add_google_analytics() {
    ?>
    <script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_TRACKING_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'YOUR_TRACKING_ID');
    </script>
    <?php
}
add_action('wp_head', 'codebykp_add_google_analytics');


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search