Skip to content

Instantly share code, notes, and snippets.

@brandondove
Last active July 31, 2020 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandondove/470fb3a01fa9b74362f8dc78296d904c to your computer and use it in GitHub Desktop.
Save brandondove/470fb3a01fa9b74362f8dc78296d904c to your computer and use it in GitHub Desktop.
<?php
/**
* Allows you to modify the css classes that are applied to an ad unit so you can style each unit individually
*/
function example_adsanity_post_class( $classes = array(), $post = false ) {
// Adds a dynamic class that utilizes data from the post object
if ( FALSE !== $post && $post instanceof WP_Post ) {
$classes[] = sprintf( 'custom-%d', $post->ID );
}
// Adds a static class to all ads
$classes[] = 'special-ad';
return $classes;
}
add_filter( 'adsanity_post_class', 'example_adsanity_post_class', 10, 2 );
@djmtype
Copy link

djmtype commented Jul 21, 2020

You have a typo on line 8.

Should be:

if ( FALSE !== $post && $post instanceof WP_Post ) {

@brandondove
Copy link
Author

Great catch, @djmtype! I've fixed the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment