Support » Plugin: Video Embed & Thumbnail Generator » Image not attached to video

  • Resolved Fobstar

    (@fobstar)


    Hi there,

    I’m trying to retrieve the video thumbnail otherwise display the mime icon instead. See code below.

    if (wp_attachment_is_image( $attach_id)) {
    $image = wp_get_attachment_image_src( $attach_id, ‘thumbnail’ );
    $image = $image[0];
    } else {
    $image = wp_mime_type_icon( $attach_id );

    However every time the mime is displayed instead, which means the image is not attached to the video? This cose used to work but for some reason it no longer does. What am I doing wrong and how do I display the thumbnails generated by your plugin? Many thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Kyle Gilman

    (@kylegilman)

    I recently removed a function in my plugin that replaced the mime type icon for videos with their thumbnail if it exists. It was a hack that caused problems with some sites and WordPress has started showing thumbnails in the backend without that function anyway. My guess is wp_attachment_is_image($attach_id) always returns false and you were getting the mime icon every time. I’ll need more context to come up with a replacement function. How are you defining $attach_id ?

    Fobstar

    (@fobstar)

    Hi Kyle, yes thats correct. Video thumbnails are appearing fine in backend WP Media, just not on my frontend upload page anymore. I use the code to display thumbnails for all video and image as they are uploaded to a post. Works fine for image thumbnails still so just trying to get video thumbnails working again. Here is how $attach_id is defined.

    $file_loc = $uploaded_file[‘file’];
    $file_name = basename( $upload_data[‘name’] );
    $file_type = wp_check_filetype( $file_name );
    $attachment = array(
    ‘post_mime_type’ => $file_type[‘type’],
    ‘post_title’ => preg_replace( ‘/\.[^.]+$/’, ”, basename( $file_name ) ),
    ‘post_content’ => ”,
    ‘post_status’ => ‘inherit’ );

    $attach_id = wp_insert_attachment( $attachment, $file_loc );

    Plugin Author Kyle Gilman

    (@kylegilman)

    If the uploaded file is a video then wp_attachment_is_image($attach_id) will return false. The function is not testing children of $attach_id, it’s testing if $attach_id itself is an image. I would try something like this:

    if (get_the_post_thumbnail_url($attach_id)) {
    $image = get_the_post_thumbnail_url($attach_id, 'thumbnail');
    } else {
    $image = wp_mime_type_icon( $attach_id );

    Bingo! Works perfectly, thank you Kyle. Much appreciated 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Image not attached to video’ is closed to new replies.