Last active
August 29, 2015 14:16
-
-
Save samediamba/912fff30fa4bb84c7fb6 to your computer and use it in GitHub Desktop.
Default and Conditional Featured Image for WP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //* You can do without this opening tag | |
//* Courtesy of http://www.engagewp.com/set-default-conditional-featured-images-wordpress/ | |
/** | |
* This snippet requires the Deafult Featured Image plugin to be installed | |
* https://wordpress.org/plugins/default-featured-image/ | |
* It replaces the image you selected as your default with one of your choosing | |
* Should be added to the Functionality Plugin | |
*/ | |
//* Set default post thumbnail | |
add_filter( 'dfi_thumbnail_id', 'rv_conditional_default_thumbnails' ); | |
function rv_conditional_default_thumbnails( $object_id ) { | |
if ( is_singular( 'staff' ) ) { /*Displays featured image for the staff CPT*/ | |
$object_id = 3020; /*[REPLACEABLE] This is the Image ID*/ | |
} | |
elseif ( is_singular( 'church_directory' ) ) { /*Displays featured image for the staff CPT*/ | |
$object_id = 3019; /*[REPLACEABLE] This is the Image ID*/ | |
} | |
elseif ( is_singular( 'book' ) ) { /*Displays featured image for the staff CPT*/ | |
$object_id = 3018; /*[REPLACEABLE] This is the Image ID*/ | |
} | |
return $object_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment