This tutorial will help you add a custom Download Button at the end of any post (or anywhere) you want to display with ability to change the download link with simple custom field. Works best for Websites like Photoshop Tutorials or any site where you provide freebies or download links.
Let’s see hows it done.
First you have to design or get an image from the internet, you want to use as a Download Button. Now we start the coding thing.
Go to your Theme Editor Page “Dashboard > Appearance > Theme Editor” and open Single.php
>Single.php is responsible for displaying your Post Page.
- Find <?php the_content(); ?> in Single.php. It calls content from the Post.
- Add the following code after <?php the_content(); ?> code, where you want the download button to display.
<?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?>
<a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"<img src="IMG URL" border="0"></a>
<?php } ?>
If you want to style your Download Image, wrap it with a div and define a custom style which we will later on add to the stylesheet.css of your theme file. (this is totally optional but suggested)
<div id="mydownload">
<?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?>
<a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"<img src="IMG URL" border="0"></a>
<?php } ?>
</div>
- Now after defining the ‘mydownload’ id to the code, lets head over to the stylesheet.css and add some custom styles. This you have to do yourself depending on your theme and stylesheet add padding, margins or whatever you find suitable.
- Create a new style at the end of style sheet with #mydownload {} and add any styles you want in between the brackets.
- We added the code to call the custom field in the single.php. Now lets see if this thing works.
- Go to your Post Page Dashboad > Post > Add New.
- Scroll down to your custom field box and add a new custom field
Publish and see if your image is showing correctly.
You may have to edit code place or style sheet a couple of times to get some good results depending on your theme.






Thanks for the great post.:)
Saad´s last blog ..How to Download YouTube Videos with Chrome Extensions
[Reply]