Can’t add script immediately after the opening tag on login page?

Question

I am trying to add the following Google Tag Manager script immediately after the opening <body> tag on the WordPress login page.

Code that I want to insert

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

What I have tried

Based on the solution given here: Adding body class to login page?, I tried the following code:

function my_custom_code2($classes){
?>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P3CWDSQ"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->";
<?php 
}

add_filter( 'login_body_class', 'my_custom_code2' );

Results

It does not work. Does anyone know how I can fix this?

Thanks.

0
xojijog684 4 months 0 Answers 9 views 0

Leave an answer