Skip to content

Instantly share code, notes, and snippets.

@BoyetDgte
Last active August 7, 2020 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BoyetDgte/8a51c968a94ddd277a2192fb07b4bdd4 to your computer and use it in GitHub Desktop.
Save BoyetDgte/8a51c968a94ddd277a2192fb07b4bdd4 to your computer and use it in GitHub Desktop.
Exclude Scripts (Google tags, FB Pixel) on all blog posts and the blog page on a specific Multisite. Filter is added on Head, Footer and Body tag.
function excluding_blogs_header() {
// exclude from Posts Page (blog) page and all blog posts on the Main site (multisite)
if( !is_single() && !is_home() && 1 === get_current_blog_id() ) {
$code = "<script> Your script here </script>";
} else {
  $code = null;
}
  echo $code;
}
add_action( 'wp_head', 'excluding_blogs_header', 15 );
function excluding_blogs_footer() {
if( !is_single() && !is_home() && 1 === get_current_blog_id() ) {
$code = "<script> Your script here </script>";
} else {
  $code = null;
}
  echo $code;
}
add_action( 'wp_footer', 'excluding_blogs_footer', 15 );
function excluding_blogs_body() {
if( !is_single() && !is_home() && 1 === get_current_blog_id() ) {
$code = "<script> Your script here </script>";
} else {
  $code = null;
}
  echo $code;
}
add_action( 'wp_body_open', 'excluding_blogs_body', 15 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment