Created
May 22, 2019 10:26
-
-
Save damiencarbery/2b57faa9d0b142040ecde294bfd666b0 to your computer and use it in GitHub Desktop.
Add Media Playlist Download link - response to https://www.damiencarbery.com/2017/02/add-download-link-to-wordpress-audio-player/#comment-2914
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Add Media Playlist Download link | |
Plugin URI: https://wordpress.stackexchange.com/a/292952 | |
Description: Adding a download link to native WordPress playlist - StackExchange answer | |
Author: Blix | |
Version: 0.1 | |
*/ | |
// This code is an answer to | |
// https://wordpress.stackexchange.com/questions/292585/adding-a-download-link-to-native-wordpress-playlist | |
// Answer: https://wordpress.stackexchange.com/a/292952 | |
add_action( 'wp_head', 'dcwd_change_playlist' ); | |
function dcwd_change_playlist() { | |
?> | |
<script type="text/html" id="tmpl-wp-playlist-current-item"> | |
<# if ( data.image ) { #> | |
<img src="{{ data.thumb.src }}"/> | |
<# } #> | |
<div class="wp-playlist-caption"> | |
<span class="wp-playlist-item-meta wp-playlist-item-title">{{ data.title }}</span> | |
<# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #> | |
<# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #> | |
</div> | |
</script> | |
<script type="text/html" id="tmpl-wp-playlist-item"> | |
<div class="wp-playlist-item"> | |
<a class="wp-playlist-caption" href="{{ data.src }}"> | |
{{ data.index ? ( data.index + '. ' ) : '' }} | |
<# if ( data.caption ) { #> | |
{{ data.caption }} | |
<# } else { #> | |
<span class="wp-playlist-item-title">{{{ data.title }}}</span> | |
<# if ( data.artists && data.meta.artist ) { #> | |
<span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span> | |
<# } #> | |
<# } #> | |
</a> | |
<# if ( data.meta.length_formatted ) { #> | |
<div class="wp-playlist-item-length">{{ data.meta.length_formatted }}</div> | |
<# } #> | |
</div> | |
<!-- BEGIN CHANGES --> | |
<a href="{{ data.src }}" class="wpse-download" download=""><i class="fa fa-download" title="Download" aria-hidden="true"></i></a> | |
<!-- END CHANGES --> | |
</script> | |
<!--<style> | |
/*playlist title - more to right*/ | |
.wp-playlist-item-title { | |
padding-left:25px | |
} | |
/*download link styles - move within playlist & to left of playlist title*/ | |
.wpse-download { | |
margin-top: -22px; | |
padding-left:5px; | |
position: absolute; | |
} | |
/*change color of icon*/ | |
.wpse-download { | |
color:white!important; | |
} | |
/*change hover / active state of download icon*/ | |
.wpse-download:hover, .wpse-download:visited | |
{ | |
color:#aaa!important; | |
} | |
</style>--> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment