Title: wp_read_audio_metadata
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_read_audio_metadata( string $file ): array|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#wp--skip-link--target)

Retrieves metadata from an audio file’s ID3 tags.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#parameters)󠁿

 `$file`stringrequired

Path to file.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#return)󠁿

 array|false Returns array of metadata, if found.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#source)󠁿

    ```php
    function wp_read_audio_metadata( $file ) {
    	if ( ! file_exists( $file ) ) {
    		return false;
    	}

    	$metadata = array();

    	if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
    		define( 'GETID3_TEMP_DIR', get_temp_dir() );
    	}

    	if ( ! class_exists( 'getID3', false ) ) {
    		require ABSPATH . WPINC . '/ID3/getid3.php';
    	}

    	$id3 = new getID3();
    	// Required to get the `created_timestamp` value.
    	$id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName

    	$data = $id3->analyze( $file );

    	if ( ! empty( $data['audio'] ) ) {
    		unset( $data['audio']['streams'] );
    		$metadata = $data['audio'];
    	}

    	if ( ! empty( $data['fileformat'] ) ) {
    		$metadata['fileformat'] = $data['fileformat'];
    	}

    	if ( ! empty( $data['filesize'] ) ) {
    		$metadata['filesize'] = (int) $data['filesize'];
    	}

    	if ( ! empty( $data['mime_type'] ) ) {
    		$metadata['mime_type'] = $data['mime_type'];
    	}

    	if ( ! empty( $data['playtime_seconds'] ) ) {
    		$metadata['length'] = (int) round( $data['playtime_seconds'] );
    	}

    	if ( ! empty( $data['playtime_string'] ) ) {
    		$metadata['length_formatted'] = $data['playtime_string'];
    	}

    	if ( empty( $metadata['created_timestamp'] ) ) {
    		$created_timestamp = wp_get_media_creation_timestamp( $data );

    		if ( false !== $created_timestamp ) {
    			$metadata['created_timestamp'] = $created_timestamp;
    		}
    	}

    	wp_add_id3_tag_data( $metadata, $data );

    	$file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null;

    	/**
    	 * Filters the array of metadata retrieved from an audio file.
    	 *
    	 * In core, usually this selection is what is stored.
    	 * More complete data can be parsed from the `$data` parameter.
    	 *
    	 * @since 6.1.0
    	 *
    	 * @param array       $metadata    Filtered audio metadata.
    	 * @param string      $file        Path to audio file.
    	 * @param string|null $file_format File format of audio, as analyzed by getID3.
    	 *                                 Null if unknown.
    	 * @param array       $data        Raw metadata from getID3.
    	 */
    	return apply_filters( 'wp_read_audio_metadata', $metadata, $file, $file_format, $data );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/media.php#L3686)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/media.php#L3686-L3759)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_read_audio_metadata’, array $metadata, string $file, string|null $file_format, array $data )](https://developer.wordpress.org/reference/hooks/wp_read_audio_metadata/)

Filters the array of metadata retrieved from an audio file.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_media_creation_timestamp()](https://developer.wordpress.org/reference/functions/wp_get_media_creation_timestamp/)`wp-admin/includes/media.php` |

Parses creation date from media metadata.

  | 
| [wp_add_id3_tag_data()](https://developer.wordpress.org/reference/functions/wp_add_id3_tag_data/)`wp-admin/includes/media.php` |

Parses ID3v2, ID3v1, and getID3 comments to extract usable data.

  | 
| [get_temp_dir()](https://developer.wordpress.org/reference/functions/get_temp_dir/)`wp-includes/functions.php` |

Determines a writable directory for temporary files.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#)

| Used by | Description | 
| [wp_generate_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_generate_attachment_metadata/)`wp-admin/includes/image.php` |

Generates attachment meta data and create image sub-sizes for images.

  | 
| [media_handle_upload()](https://developer.wordpress.org/reference/functions/media_handle_upload/)`wp-admin/includes/media.php` |

Saves a file submitted from a POST request and create an attachment post for it.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#comment-content-1418)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/#comment-1418)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F%23comment-1418)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F%23comment-1418)
 4.  **Example**
 5.      ```php
         $uploads = wp_upload_dir();
         $uploads_dir = ( $uploads['baseurl'] . $uploads['subdir'] );
         $file = $uploads_dir . '/example.mp3';
         $metadata = wp_read_audio_metadata( $file );
         print "Audio is " . $metadata['length'] . ' seconds long';
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F%3Freplytocom%3D1418%23feedback-editor-1418)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/?output_format=md#comment-content-6515)
 8.    [Lucas Marini Falbo](https://profiles.wordpress.org/lucasmarinifalbo/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/#comment-6515)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F%23comment-6515)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F%23comment-6515)
 10. This function does not work on the front-end, so if you need to call it on the
     front-end, first you need to require the library.
 11.     ```php
         // Requires the media library that unlocks the function
         require_once ABSPATH . 'wp-admin/includes/media.php';
     
         // Get the audio metadata
         $meta = wp_read_audio_metadata( $path );
         ```
     
 12. One important detail that people misses is that the function expects the file 
     path, not the url.
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F%3Freplytocom%3D6515%23feedback-editor-6515)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_read_audio_metadata%2F)
before being able to contribute a note or feedback.