Hey @vital14,
Those filter hooks should work AFAIK so please show me how you’re using them so I can have a look.
- wpp_should_track
function exclude_page_from_tracking($should_track, $post_id) { $excluded_pages = array(4857); // Example page ID to exclude
if (in_array($post_id, $excluded_pages)) { return false; } return $should_track; } add_filter(‘wpp_should_track’, ‘exclude_page_from_tracking’, 10, 2);
2. wpp_pre_update_views
function prevent_wpp_views_update($views, $id) { $excluded_pages = array(4857);
if (in_array($id, $excluded_pages)) { return 0; } return $views; }
add_filter(‘wpp_pre_update_views’, ‘prevent_wpp_views_update’, 10, 2);
I am adding the code using the Code Snippets plugin.!!!!!
Hey @vital14, thanks for sharing your code.
I’ll correct myself here, my previous comment wasn’t correct:
wpp_should_track is not a valid filter hook, it doesn’t exist. Not sure where you got that from 😛
- wpp_pre_update_views is an action hook, not a filter hook. That code you have there was never going to work in the first place.
Delete those two code snippets, then try this one out instead:
/**
* Excludes specific post/page IDs from WPP's views tracker.
*
* @param array $trackable_post_types An array of trackable post types
* @return array $trackable_post_types An array of trackable post types
*/
function wpp_exclude_items_from_tracking($trackable_post_types) {
$excluded_IDs = array(4857);
$post_ID = get_queried_object_id();
if ( $post_ID && in_array($post_ID, $excluded_IDs) ) {
$trackable_post_types = ['donottrack'];
}
return $trackable_post_types;
}
add_filter('wpp_trackable_post_types', 'wpp_exclude_items_from_tracking', 10);