Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Created February 22, 2016 14:47
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 jtsternberg/d9013a849bce297c5bff to your computer and use it in GitHub Desktop.
Save jtsternberg/d9013a849bce297c5bff to your computer and use it in GitHub Desktop.
blacklist/exclude page paths if the path starts with a certain string (for Google Analytics Top Content Widget)
<?php
function gtc_pages_filter_automatically_remove_items( $pages ) {
$string_to_exclude = '/category/';
foreach ( $pages as $index => $page ) {
// if path contains our excluded string, then remove it.
if ( false !== strpos( $page['path'], $string_to_exclude ) ) {
unset( $pages[ $index ] );
}
}
return $pages;
}
add_filter( 'gtc_pages_filter', 'gtc_pages_filter_automatically_remove_items' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment