Tagged: custom post types
-
AuthorPosts
-
November 8, 2014 at 6:48 pm #348196
Hi!
I use following code i found in support and that works fine for a single CPT “Meetings”, but how is the code for several CPT’s?:
/*
Add a checkbox to the featured image metabox
*/
if(!function_exists(‘theme_featured_image_meta’))
{
add_filter( ‘admin_post_thumbnail_html’, ‘theme_featured_image_meta’);function theme_featured_image_meta( $content )
{
global $post_type;if($post_type == “meeting”)
{
$text = __( “Don’t display image on single post”, ‘avia_framework’ );
$id = ‘_avia_hide_featured_image’;
$value = esc_attr( get_post_meta( $post->ID, $id, true ) );
$selected = !empty($value) ? “checked=’checked'” : “”;$label = ‘<label for=”‘ . $id . ‘” class=”selectit”><input ‘.$selected.’ name=”‘ . $id . ‘” type=”checkbox” id=”‘ . $id . ‘” value=”1″ > ‘ . $text .'</label>’;
return $content .= $label;
}return $content;
}
}Even better would be a setting at Theme Options to hide featured images on all single posts, pages and cpt’s…
Thanks for your help
Peter- This topic was modified 10 years ago by pegasso4444.
November 9, 2014 at 10:32 pm #348476Hey Peter!
Try with this:
<?php if(!function_exists('avia_theme_featured_image_meta')) { add_filter( 'admin_post_thumbnail_html', 'avia_theme_featured_image_meta'); function avia_theme_featured_image_meta( $content ) { global $post, $post_type; if($post_type == "meeting" || $post_type == "cpt1" || $post_type == "cpt2" || $post_type == "cpt3") { $text = __( "Don't display image on single post", 'avia_framework' ); $id = '_avia_hide_featured_image'; $value = esc_attr( get_post_meta( $post->ID, $id, true ) ); $selected = !empty($value) ? "checked='checked'" : ""; $label = '<label for="' . $id . '" class="selectit"><input '.$selected.' name="' . $id . '" type="checkbox" id="' . $id . '" value="1" > ' . $text .'</label>'; return $content .= $label; } return $content; } }
Replace cpt1, cpt2, cpt3 by the other CPT slugs.
Best regards,
JosueNovember 13, 2014 at 5:47 pm #350794Hi Josue!
Works fine.
Thanks for your help
Peter -
AuthorPosts
- The topic ‘Checkbox to hide featured images in cpt’ is closed to new replies.