I have had success at creating an RSS feed with enclosures containing episodes of my podcast by simply creating a post and inserting an mp3 file from my media library into it via the robust Add Media functionality of the post editor. However, I have found that the RSS feed created from these posts includes an enclosure for each mp3 file with its length attribute set to zero:

<enclosure url="http://example.com/wp-content/uploads/2020/05/myfile.mp3" length="0" type="audio/mpeg" />

How can I set the length attribute of the enclosure so that it is accurate?

I am not interested in changing the format of my posts, so any plugin-based solution should not require a significantly different workflow when posting.

1 Answer 1


The enclosure tag will implement via the function rss_enclosure. This function has the filter hook rss_enclosure. So you can change the result via this hook.

Here is a longer post about the how-to for audio files, this should help you.

  • 1
    Thank so much! It turns out the length attribute actually holds the file size in bytes. Duration goes inside the <itunes:duration> element. I managed to use the guide found in the link you provided, combined with the wp_get_attachment_metadata() function to get the duration from the file itself. In the guide, they simply use one of the audio file's meta fields to manually set the length.
    – Keyslinger
    Commented Mar 11, 2021 at 5:51

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.