Skip to content

Instantly share code, notes, and snippets.

@Nicscott01
Last active May 8, 2025 19:49
Show Gist options
  • Save Nicscott01/82d68284ac2466c0c4ea9a9b792e6314 to your computer and use it in GitHub Desktop.
Save Nicscott01/82d68284ac2466c0c4ea9a9b792e6314 to your computer and use it in GitHub Desktop.
Add a gtag to Google Tag Manager Code output by RankMath
<?php
/**
* Add a gtag() line to an existing googletagmanager script
* that is installed by Rank Math SEO plugin.
*/
add_filter( 'rank_math/analytics/gtag', function( $gtag ) {
$gtag['inline'] .= "gtag('config', 'AW-XXXXXXX');";
return $gtag;
}, 10, 2 );
@Nicscott01
Copy link
Author

I used this code to add a Google Ad tag to my website that's using Rank Math SEO for outputting Google Analytics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment