Featured Image added by programming is displayed with a size of 1px
-
Hi everybody,
I have a bug. I add post thumbnail by programming but is displayed with 1px height and 1 px width like this :
<img class="scale-with-grid wp-post-image" height="1" alt="4442451861_29185dfe82_b1-438x438" src="https://localhost:8888/wordpress-test/wp-content/uploads//2014/01/4442451861_29185dfe82_b1-438x438.jpg">
My code to add featured image is :
$filename = get_user_meta($userID, 'image_profil',true); $wp_filetype = wp_check_filetype(basename($filename), null ); $wp_upload_dir = wp_upload_dir(); $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $filename); require_once( ABSPATH . 'wp-admin/includes/image.php' ); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail( $post_id, $attach_id );
What do you think about it ?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Featured Image added by programming is displayed with a size of 1px’ is closed to new replies.