How to add snippet to one blog only in multisite

Hi, thanks for your reply. I inserted your code to mu-plugins. However, something went wrong because I now get a ‘white screen’. I probably inserted the script into your code at the wrong position (before the ‘<?php’ tag (but same result if within php tag) ; see:

<?php

/* Adds a code snippet to the header of all pages of one blog within a multisite */

add_action(‘wp_head’, ‘your_function_name’

function your_function_name(){

$blogID = ‘8’;

$pageID = ‘Your Page ID’;

$blog_id = get_current_blog_id();

$page_id = get_the_ID();

if ($blog_id == $blogID ) {

?>

// PASTE HEADER CODE HERE FOR ALL BLOG PAGES

<!– Global site tag (gtag.js) – Google Ads: 855663229 –>

<script async src=”https://www.googletagmanager.com/gtag/js?id=AW-855663229″></script&gt;

<script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(‘js’, new Date()); gtag(‘config’, ‘AW-855663229’

<?php

}

if ($blog_id == $blogID && $page_id == $pageID) {

?>

// PASTE HEADER CODE HERE for only One PAGE

<?php

}

Related Articles

Leave a Reply

Back to top button