|
/ Documentation /Developers/ Including Custom Post Types in Scanning and the Cookie Policy Picker

Including Custom Post Types in Scanning and the Cookie Policy Picker

SureCookie lets you pick which content to scan for cookies, and which page to use as your Cookie Policy. By default, both pickers list your Pages. If your site uses custom post types (CPTs) such as products, docs, or landing pages, you can add them to either picker so their cookies are covered and their content is selectable.

This is a developer feature. You enable your post types with a small filter added to your theme’s functions.php file or a custom plugin. It works in the free version of SureCookie.

Available in SureCookie 1.2.4 and later.

What’s Supported by Default

Out of the box, both pickers list published Pages only. This keeps behavior predictable and avoids flooding the dropdown with content you rarely need to scan.

Two places use this list:

  • Cookie Scanner: Under SureCookie → Cookie Manager → Cookie Scanning, the Select Content picker chooses which items the scanner visits. Automatic Scanning uses the same list for its Selected and All Published Content scopes.
  • Cookie Policy page: Under SureCookie → Cookie Manager → Cookie Policy, the Cookie Policy Page picker chooses the page that visitors see as your policy.

When a picker shows more than one post type, results are grouped under a heading for each type (for example Pages, Posts, or your custom type’s label). A single type shows a plain list with no heading.

Adding Your Custom Post Types

Use the surecookie_searchable_post_types filter to add post types to the list. The filter receives an array of post type slugs (keyed by slug) and a $context string that tells you which picker is asking.

Return the array with your post type added. The post type must be registered with public => true, otherwise SureCookie ignores it.

Add a Post Type to Both Pickers

This example adds a product post type to the scanner and the Cookie Policy picker:

add_filter( 'surecookie_searchable_post_types', function ( $post_types ) {
    $post_types['product'] = 'product';
    return $post_types;
} );

Add a Post Type to One Picker Only

The second argument, $context, is 'scanner' for the Cookie Scanner and 'policy' for the Cookie Policy picker. Branch on it to target a single surface.

This example makes a landing_page type selectable in the scanner only, leaving the Cookie Policy picker unchanged:

add_filter( 'surecookie_searchable_post_types', function ( $post_types, $context ) {
    if ( 'scanner' === $context ) {
        $post_types['docs'] = 'docs';
    }
    return $post_types;
}, 10, 2 );

To accept the $context argument, set the filter’s accepted-args count to 2 (the 10, 2 at the end).

Include Blog Posts

Blog posts are a built-in type, not a CPT, and are not listed by default. Add them the same way:

add_filter( 'surecookie_searchable_post_types', function ( $post_types ) {
    $post_types['post'] = 'post';
    return $post_types;
} );

How It Behaves

  • Grouping: Once more than one type is selectable, the dropdown groups results under a heading per type, so a Page and a Post with the same title are easy to tell apart.
  • Automatic Scanning: The All Published Content scope scans published Posts and Pages plus any post types you have opted into the scanner, so scheduled scans stay in sync with what you can pick manually.
  • Public types only: SureCookie only lists types registered with public => true. Non-public, non-existent, or media (attachment) types are filtered out even if a snippet tries to add them.

Troubleshooting

  • My custom post type doesn’t appear in the picker. Confirm the type is registered with public => true, that your filter returns the modified array, and that you have at least one published item of that type. If you targeted a single picker with $context, check you are looking at the right one.
  • The Select Content picker is greyed out. Cookie scanning runs through SureCookie’s cloud scanner, which needs a publicly reachable URL. It is unavailable on local or staging sites that the scanner cannot reach. Scanning becomes available once your site is live on a public domain.
  • Two items show the same name. That is expected when a Page and a Post (or a CPT) share a title. They are separated under their type headings, and SureCookie tracks each by its unique ID, so your selection is always correct.

Next Steps

After adding a post type, open the relevant picker, search for one of its items, and confirm it appears under the right heading. Then run a scan or save your Cookie Policy page as usual.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top