WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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!

share|improve this question
What's your problem in creating that shortcode? What have you done so far? Please add the code you've done so far and explain the problem you've run into. – hakre Jul 14 '11 at 18:58
Probably a duplicate of How do I create short codes for my wordpress themes? - it explains how to create a shortcode and has example code in it's answer. – hakre Jul 14 '11 at 18:59
up vote 2 down vote accepted
// 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;
share|improve this answer
thanks so much, it works perfectly. i'm sure i'll be able to take it from there and expand it if needed. @hakre, thanks for the link, too. – pereyra Jul 14 '11 at 20:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.