I need to show length of a video attachment.

Video is in media library. I put the video normally, by wp administration.

I am using this code in content.php, inside the loop, after this:

 <?php the_content( sprintf(
                __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentythirteen' ),
                the_title( '<span class="screen-reader-text">', '</span>', false )  ) );

I add this code:

     $video_meta = get_post_meta( $attachment_id , '_wp_attachment_metadata', true );
echo $video_meta['length_formatted'];  

But i don't know how to get $attachment_id.

I am using twentythirteen theme. Last versione of WP.

Is it possible show length?

  • If you can determine the URL, then you can use get_attachment_id() by @Rarst. – Nicolai Jul 24 '15 at 14:20
  • Where are you using this? – birgire Jul 24 '15 at 14:30
  • how can i determine URL and then how can i use get_attachment_id() ? – user3720387 Jul 24 '15 at 15:42
  • I am using that code in content.php, into the loop, after: <?php the_content( sprintf( ... ?> – user3720387 Jul 24 '15 at 15:43
  • what's the context - is it for an attachment page? Or is it for the post parent, where you could have an array of video attachments. Please update your question with all the related info, from the comments. – birgire Jul 24 '15 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.