RSS audio enclosures have length of zero (podcast duration is missing)
-
19-05-2021 - |
Question
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.
Solution
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.