Jean-Marc Amiaud

Filter wordpress content to replace link by your player code

by on Nov.30, 2010, under WordPress

When you insert a media into a wordpress article, the media library insert just a simple link into your content.
It’s possible to replace this link by your player, for exemple, using the_content wordpress filter function.

  1. First step, add your filter function :add_filter('the_content', myFilterFunction);
  2. Second step, write your filter function to parse your required link type (.mp3, .flv, …) to replace :
    function myFilterFunction($content) {
    $content = preg_replace_callback('#^(<p>)?<a.*href=[\'"](http://.*/.*\.mp3)[\'"].*>.*</a>(</p>|<br />)?#im', myPlayerWriterCallBack, $content);
    }
    function myPlayerWriterCallBack($match) {
    // Use $match[2] to get original link url
    }

Example with my little flash audio player.

Foo Fighters – All my life

:

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!