view raw
srthompers srthompers - 1 year ago 45
SQL Question

Changing how audio embed shortcodes are generated in Wordpress

I have a rather annoying problem: I have a wordpress website that, among other things, serves audio files. Wordpress does a nice job of filtering any media inserts to a post and putting a player in, but this isn't much good for allowing downloads of the file as well. Ideally I'd want to change the code that generates the audio player shortcode and add

<a href="URL">Click here to download mp3.</a>
after the
tag, but my PHP is pretty much non-existent.

My current approach is to use python (which I know well) to write an hourly cron script which plays with the mysql database directly using the python mysql connector. If it runs hourly and looks for posts made in the last hour which contain the string
, pulls out the url for the audio file, and uses it to construct a link to append afterwards. The effect of this is the same, with a maximum time delay of one hour between the post being made and the link being available. When I've finished coding it it should work, but I'm sure it's not the best approach.

Any suggestions?


This should do it (add this to your functions.php file)

function wp_audio_shortcode_dowload_link( $html, $atts, $audio, $post_id, $library ) {
    $html .='<br><a href="'.$atts['src'].'">Download</a>';
    return $html;

add_filter( 'wp_audio_shortcode','wp_audio_shortcode_dowload_link',5,10);