Chad
(@lynneandchad)
This article should help you – you’d have to tailor the code to target those two post types.
Thread Starter
yonk
(@yonk)
thank you !
But I’m really not an expert…
I put this code into function.php (I’m doing with genesis framework, so don’t have template)
add_action(‘init’,’album_photo_thumbnail’);
function album_photo_thumbnail(){
if ( is_post_type(‘albumphoto’)) {
the_thumbnail(‘thumbnail’, ‘wp-content/upload/2015/05/photo-icon.jpg’)
}
}
But it’s not working…
Can’t I create the thumbnail into the function that create the post type ?
Chad
(@lynneandchad)
Ah, Genesis 🙂 My favorite framework.
I don’t think you can add a default thumbnail when creating a post type, but WPSites has a good tutorial that I’ve adapted to what you’re trying to accomplish
add_filter( 'genesis_pre_get_image', 'default_featured_image_when_not_set', 10, 1 );
function default_featured_image_when_not_set( $post ) {
if ( 'albumphoto' == get_post_type() ) :
echo get_post_type() . '<img src="wp-content/upload/2015/05/photo-icon.jpg" />';
else:
return $post;
endif;
}
You may need to adjust some of the styling of the image, but that’s the easy part 🙂
Thread Starter
yonk
(@yonk)
I changed a little bit your code because it didn’t work :
add_filter( 'genesis_pre_get_image', 'default_featured_image_for_albumphoto', 10, 1 );
function default_featured_image_for_albumphoto( $post ) {
if ( 'albumphoto' == get_post_type() ) :
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/photo-icon.jpg" />';
else:
return $post;
endif;
}
But I wouldn’t have done it all by myself…
I thank you very very much !
Chad
(@lynneandchad)
Excellent. Sorry, that second get_post_type() shouldn’t have been there. I meant to remove it.
Good call on updating the image path 🙂