Add this code in functions.php for Add Select Metabox in WordPress Custom and Default Post Types:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
add_action( 'add_meta_boxes', 'feature_image' ); function feature_image($post){ add_meta_box('feature_image', 'Featured Image Size', 'featured_image_size_meta', $post->post_type, 'normal' , 'high'); } add_action('save_post', 'save_metabox'); function save_metabox(){ global $post; if(isset($_POST["featured_image_size"])){ $meta_value = $_POST['featured_image_size']; update_post_meta($post->ID, 'featured_image_size_meta', $meta_value); } } function featured_image_size_meta($post){ $meta_value = get_post_meta($post->ID, 'featured_image_size_meta', true); //true ensures you get just one value instead of an array ?> <label>Choose the Featured Image Size : </label> <select name="featured_image_size" id="featured_image_size"> <option value="thumbnail" <?php selected( $meta_value, 'thumbnail' ); ?>>Thumbnail</option> <option value="medium" <?php selected( $meta_value, 'medium' ); ?>>Medium</option> <option value="large" <?php selected( $meta_value, 'large' ); ?>>Large</option> <option value="full" <?php selected( $meta_value, 'full' ); ?>>Full</option> </select> <?php } |