How to Add a Download Page for Single Post on WordPress?

If you are using WordPress as a content management system to build a website to share files with others. Then you must want to know how to add a download page for a single on WordPress.  At the same time, with a single file download page can increase the number of page views.

There are two choices for you to achieve the file download function for every single file:

  1. By adding some code to implement it.
  2. Install some popular download manager plugins, such as WordPress Download Manager, Download Monitor, Easy Digital Downloads…

Here, firstly, we will share the way to implement the file download function for each post, then to recommend the most popular download manager plugins for WordPress.

Step 1: Create a page-download.php file

How to create a page-download.php file?

Firstly, enter the theme folder, then copy page.php name as page-download.php.

Then you should paste the first code snippet as followed to the page-download.php file.

*template name: page-download template
/*…. here are the original page code…. */
$pid = isset( $_GET[‘pid’] ) ? trim(htmlspecialchars($_GET[‘pid’], ENT_QUOTES)) : ”;
if( !$pid ) { wp_redirect( home_url() );}
$title = get_the_title($pid);
$values1 = get_post_custom_values(‘git_download_name’,$pid);
empty($values1) ? Header(‘Location:/’) : $theCode1 = $values1[0];
$values2 = get_post_custom_values(‘git_download_size’,$pid);
empty($values2) ? Header(‘Location:/’) : $theCode2 = $values2[0];
$values3 = get_post_custom_values(‘git_download_link’,$pid);
empty($values3) ? Header(‘Location:/’) : $theCode3 = $values3[0];

Step 2: Add CSS style code for the download page

Add the following CSS style code after the first PHP snippet in page-download.php. Of course, you can also design your own style.

<style type=”text/css”>
    #filelink a:hover{
        background:#4094EF none repeat scroll 0 0;
    #filelink a{
        margin:25px 15px 25px 0px;
        padding:5px 50px;
        font-family:”Microsoft YaHei”;
        border:1px solid #4094EF;
        box-shadow:0 1px 3px rgba(0,0,0,.1)

Add the following code before the output function < ?php the_content(); ?> in page-download.php.

<h2>About The Resource</h2>
<li>Sesource description:<?php echo $theCode1; ?></li>
<li>Size:<?php echo $theCode2; ?></li>
<li>Date:<?php echo get_post($pid)->post_modified; ?></li>
<h2>Free Dowload Link</h2>
<div id=”filelink” align=”left”>
if ($theCode3) {
$git_download_links = explode(“\n”, $theCode3);
foreach ($git_download_links as $git_download_link) {
$git_download_link = explode(” “, $git_download_link);
echo ‘<a href=”‘ . trim($git_download_link[0]) . ‘”target=”_blank” rel=”nofollow” data-original-title=”‘ . esc_attr(trim($git_download_link[2])) . ‘” title=”‘ . esc_attr(trim($git_download_link[2])) . ‘”>’ . trim($git_download_link[1]) . ‘</a>’;

At this time, a simple download page template is complete. Here, you need to create a page and name it as dll. Just publish it, do not visit the page, generally, the page will automatically return to the home page.

Step 3: Add a download button on the editor

Open the functions.php file in the theme folder, copy and paste the following code into the functions.php file. This code snippet is used to add a download button to the editor, then you can add download file to the post through the file download button.

function page_download($atts, $content = null) {
return ‘<a class=”lhb” href=”‘.site_url().’/dll.html?pid=’.get_the_ID().'” target=”_blank” rel=”nofollow”>Free Download</a>’;
add_shortcode(‘pdownload’, ‘page_download’);

//add edit button
function download_tags($mce_settings) {
<script type=”text/javascript”>
QTags.addButton( ‘hy_download’, ‘download’, ‘<a class=”lhb” href=”/dll.html?pid=116369″ target=”_blank” >Free Download</a>’, ” );
add_action(‘after_wp_tiny_mce’, ‘download_tags’);

Step 4: Add three custom fields

Now, all the code had been added, it’s time to create three Custom Fields:git_download_name, git_download_size, git_download_link in the dashboard of your web. The three custom fields just need be created once time.

How to Add a Download Dage for Single on WordPress.

Note: The value of download link(git_download_link) here requires a special format, the format is: link button name note, each content is separated by two spaces.

Once all work had been done, click the single-page download button in the WordPress text editor, then publish the article, then you can go to the article and click on the download button to enter a separate page.

An example download page: Free Download

The most popular download manager plugins:  WordPress Download Manager