Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #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

    #348476

    Hey 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,
    Josue

    #350794

    Hi Josue!
    Works fine.
    Thanks for your help
    Peter

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Checkbox to hide featured images in cpt’ is closed to new replies.