Answer the question
In order to leave comments, you need to log in
How to get video duration in WordPress?
I noticed that the latest build of WordPress 5.6 somehow recognizes the duration of the video.
On one of my projects, the duration of the video is set manually through additional fields.
I would like to understand which function of the WordPress media editor is responsible for displaying duration and how to get this value.
Well, a practical question - how to display the duration value in an additional field so that the content manager does not enter it manually, or how to display this value immediately in microdata?
Answer the question
In order to leave comments, you need to log in
It's about wp_read_video_metadata()
, I guess. Works initially in the admin panel, so to display on the front of the site you need to use
require_once( ABSPATH . 'wp-admin/includes/media.php' );
in the page template, and then pull the information by the ID of the uploaded file.Well, a practical question - how to display the duration value in an additional field so that the content manager does not enter it manually, or how to display this value immediately in microdata?
<?php
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$videoattachmentid = get_attached_file( X );
$videometadata = wp_read_video_metadata( $videoattachmentid );
print "Длительность видео: " . $videometadata['length_formatted'] . " секунд";
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question