Enclosures in the new WordPress 1.5

Published on 2005-02-20 by Mark VandeWettering

Well, there is some support for enclosures right out of the box in the new release of WordPress, but it could still handle a bit of help. The way I hacked this into the old version was to insert two special custom fields and then wire the templates to scan for these and output the right bits of HTML and RSS when each post was printed.

WordPress 1.5 handles things a bit differently: it will scan the post for links to urls which appear to be audio files, and then inserts a custom enclosure field in the database with the url, size and type included as a string. But since it already thinks that the URL is linked in the post, it does nothing to make the link stand out in any way.

When I updated from 1.2, I converted each of my custom fields into a format which was compatible with the new scheme, but I was then left with a dilemma: go back and patch the text of all 52 entries so that it included a link (ugly) or go ahead and modify the templates to include a customized link. I chose the latter. I found out with a bit of work that code that looks like the following works. I include it just after any template emits the_content for a post.

[php]
$encs = get_enclosed($post_ID) ;
if ($encs) {
echo ‘

‘ ;
foreach ($encs as $enc) {
echo ‘Click here to listen to the podcast.’ ;
}
echo ‘

‘;
}[/php]

Nothing too exciting, but might prove useful to you in your work.