2

When adding an audio file to WordPress, it automatically takes the title, album, artist from the ID3 tags in the mp3 file. It uses these in the playlist and audio file attachment page.

How can I make WordPress take the comment or content description tags as well?

The reason for needing this is to be able to make a custom WordPress playlist template that will show the Track Title + Comment/Description.

For example, if we had an mp3 file with the title tag Chapter One, and the comment/description: Introduction to WordPress, I would like the playlist to show:

Chapter One: Introduction to WordPress

I realize that I can change the title ID3 tag to contain that information, but I'd prefer a filter or function in WordPress that enables me to do this without having to modify the original mp3 file's ID3 tags.

And while I could play with WordPress's built in Caption field for audio files, I also want to avoid it because that has to be manually created, whereas I could populate the ID3 tags automatically using any relevant software.

1 Answer 1

4

So, two months after posting my question I finally found an answer! It is based on code I found here on WordPress StackExchange that was used in an answer to a different question. :)

I just added the following to the top of my custom playlist plugin (which is also based on an code from an answer here):

// Add id3 tags as meta keys
add_filter( 'wp_get_attachment_id3_keys', $callback_id3 = function( $fields ) 
{
    $fields['title'] = 'Track Title';
    $fields['comments'] = 'Comments';
    $fields['filesize'] = 'File Size';
    return $fields;
} );

And then in the playlist template I just added {{ data.meta.title }}, {{ data.meta.comments}}, and {{ data.meta.filesize}} where I wanted them to be shown.

The reason I added title is because the default {{ data.title }} shows the filename without the extension instead of the the actual track title written in the ID3 tags, and {{ data.meta.title }} gave me the actual ID3 tag title.

Worth noting is that I had a hard time with the comments tag because everywhere I looked at ID3 comment tags (documentations, wp metadata array, etc) it was written singular (just comment). But then I checked getID3 and found that it uses the plural form, comments. So adding the s made my ID3 comments show at last.

I am still trying to figure out how to get the filesize to show in a more readable manner (it seems to be a matter of trial and error with me). If I can't figure it out I'll ask here.

Thanks to the community here for posting all the different answers and code samples - I wouldn't have been able to figure this out without the resources here. So grateful :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.