Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Created May 4, 2015 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasgriffin/c4e9e0d2f8254f6c4cf9 to your computer and use it in GitHub Desktop.
Save thomasgriffin/c4e9e0d2f8254f6c4cf9 to your computer and use it in GitHub Desktop.
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