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

What's the best way of doing this:

On The 'Media Library' page, I would like a link next to 'View' (the 'View' that appears when you hover over a Media item) for 'Download'. The 'Download' hyperlink would link directly to the file, unlike the 'View' link which links to a template-based page with either the embedded image or a link to the non-image file.

I have a lot of PDF's in my media library that I look up regularly, having to click on 'View' and then click on the hyper-linked file name just to get to the file is a little cumbersome.

share|improve this question
up vote 0 down vote accepted

Modified version of a piece of code found in this tutorial.

add_filter('media_row_actions', 'wpse_30159_qe_download_link', 10, 2);

function wpse_30159_qe_download_link($actions, $post) {
    /* Almost sure this is not necessary. Just in case... */
    global $current_screen;
    if ( 'upload' != $current_screen->id ) 
        return $actions; 

    // if not PDF file, return default $actions
    if ( 'application/pdf' != $post->post_mime_type )
        return $actions;

    // relative path/name of the file
    $the_file = str_replace(WP_CONTENT_URL, '.', $post->guid);

    // adding the Action to the Quick Edit row
    $actions['Download'] = '<a href="'.WP_CONTENT_URL.'/download.php?file='.$the_file.'">Download</a>';

    return $actions;    

The download script resides here: /wp-content/download.php.
And here's a sample code of a force download script.

share|improve this answer

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.