Second Meta Box for Featured Image not showing anymore since last WP update
-
Hi, I searched for a long time how to add a second meta box for another featured image and I found a snippet to do it a while ago. It worked fine for a long time but since the last WP update, it doesn’t work anymore…
I didn’t modify anything, the code I use in my functions.php is still the same but the box isn’t there anymore, I can’t add a new image (but the default meta box is still there). I can’t switch to a plugin so I hope someone in this forum will be nice enough to help me. That would be really great because I don’t know much of PHP (or JS) and I can’t find what the problem is…
Here’s the code:
add_action( 'add_meta_boxes', 'custom_featured_mb_add' ); function custom_featured_mb_add(){ add_meta_box( 'custom-featured-image', 'Post Image', 'custom_featured_image_mb', 'post', 'side', 'low' ); } function custom_featured_image_mb($post){ $image_meta = 'custom_featured_image'; $image_id = get_post_meta( $post->ID, $image_meta, true ); $image_attributes = wp_get_attachment_image_src( $image_id, array(596,170)); echo '<div class="custom_uploader">'; echo '<img class="custom_media_image" src="'. $image_attributes[0] .'" width="254" style="'. ( ! $image_id ? 'display:none;' : '' ) .' margin: 10px 0 15px 0;" />'; echo '<a href="#" class="custom_media_add" style="'. (! $image_id ? '' : 'display:none;') .'">Set New Featured Image</a>'; echo '<br><a href="#" class="custom_media_remove" style="'. ( ! $image_id ? 'display:none;' : '' ) .'">Remove post image</a>'; echo '<input class="custom_media_id" type="hidden" name="'. $image_meta .'" value="'. $image_id .'">'; echo '</div>'; } add_action( 'save_post', 'custom_featured_image_mb_save' ); function custom_featured_image_mb_save( $post_id ){ //verify the metadata is set if ( isset ($_POST['custom_featured_image'])) { //save the metadata update_post_meta( $post_id, 'custom_featured_image', $_POST['custom_featured_image']); } } function featured_image_handler_enqueue() { global $typenow; if( $typenow == 'post' ) { wp_enqueue_script( 'featured-image-handler-js', get_template_directory_uri() . '/js/featured-image-handler.js', array(), '', false ); } } add_action( 'admin_enqueue_scripts', 'featured_image_handler_enqueue' );
Thanks a lot for your help! ??
- The topic ‘Second Meta Box for Featured Image not showing anymore since last WP update’ is closed to new replies.