Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exclude optin if on a certain category.
<?php
add_filter( 'optin_monster_api_output', 'tgm_om_filter_lightbox_by_category', 10, 4 );
function tgm_om_filter_lightbox_by_category( $optins, $optin, $fields, $post_id ) {
// If in a particular category, remove the lightbox.
$cat_exc = 362; // Replace with the category ID to target.
$slug = 'sjdfhsjakdkg'; // Replace with the unique slug for the lightbox you want to remove.
$categories = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'ids' ) );
foreach ( (array) $categories as $category_id ) {
if ( $category_id && $category_id == $cat_exc && in_array( $slug, $optins ) ) {
unset( $optins[ $slug ] );
break;
}
}
// Return the modified output.
return $optins;
}
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.