Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.