Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
Using wp_read_audio_metadata()

I am trying to get some metadata from an mp3 file in WordPress. Specifically the length variable. Here is a bit of my code. It's not shown here but I have included the wp-admin/includes/media.php file. When I look at my page http://beta.openskyministry.org/podcasts/ I just see empty tags for <itunes:length></itunes:length>

Let me know If you need anything else to help answer my question.

$aud_meta = wp_read_audio_metadata($aud_url); ?>

    <item>


        <title><?php the_title(); ?></title>

        <itunes:author><?php echo htmlspecialchars((get_bloginfo('name'))); ?></itunes:author>

        <itunes:summary><?php echo  htmlspecialchars(strip_tags(get_the_excerpt())); ?></itunes:summary> 

        <itunes:length><?php echo $aud_meta['length_formatted']; ?></itunes:length>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

WordPress already stores media metadata, so there's no need to go over it. Solution is as simple as:

add_action( 'wp_head', function(){
    global $post;
    if ( is_single($post) ) {
        $args = array( 
            'post_type'     => 'attachment',
            'numberposts'   => 1,
            'post_parent'   => $post->ID,
            'post_mime_type' => 'audio'
        );  
        $attachments = get_posts( $args );
        if($attachments){
            $meta = wp_get_attachment_metadata( $attachments[0]->ID );
            echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";
        }           
    }
});

For the records, wp_read_audio_metadata() expects the file path, not the URL. If needed, it should be:

$path = get_attached_file( $attachment->ID );
$meta = wp_read_audio_metadata($path);
echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";

Related: Save camera info as metadata on image upload?

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda