There’re lots of examples both here and on the internet, I’ve tried but don’t seem to be able to achieve what I need although it does feel like it should be simple enough.
Basically, I want to be able to use a shortcode like this:
[download]http://site.com/file.doc[/download]
and I need WordPress to output this:
<a class="download" href="http://site.com/file.doc">download file</a>
<a class="download" href="http://docs.google.com/viewer?embedded=true&url=http://site.com/file.doc">preview file</a>
Your help would be greatly appreciated. Thanks so much!
// Declare your shortcode
add_shortcode("download", "downloadFunction");
// Second Declare your shortcode function
function downloadFunction($att, $content, $code){
// your function is passed 3 Arguments
// $atts : this is an array of the shortcode's attributes
// $content : this is the content between the code. in your case the file url.
// $code : this is the code used. in this case it will be download.
// here we only need the $content of the shortcode which we place for the file
$return = '<a class="download" href="'.$content.'">download file</a>';
$return .= '<a class="download" href="http://docs.google.com/viewer?embedded=true&url=".$content."">preview file</a>';
// we then return the result.
return $return;
}