Download force pdf files instead of opening in a browser (wordpress)

WordPress is the best content management system. While uploading your pdf or linking your pdf in WordPress will open the pdf in view mode. you cant able to force download it as a .zip file.

But its very easy to force the .pdf, .jpeg, .png, .gif .psd, .ai and any type of files you want. All you need is just replace your target=”_blank” in anchor tag and replace it with download=”filename.pdf”

<a href="sample.pdf" download="sample.pdf">Download</a>

Best Method for force download pdf in wordpress site

For wordpress users its very easy to force download .pdf files by adding just few lines of jquery codes to the wordpress theme footer.

WordPress dashboard->appearance->theme editor->footer.php

open footer.php file in wordpress theme editor and just paste the below jquery at the bottom line .

&lt;script&gt;&lt;br /&gt;
jQuery(document).ready(function($) {&lt;br /&gt;
   $('a[href$=".pdf"]')&lt;br /&gt;
        .attr('download', '')&lt;br /&gt;
        .attr('target', '_blank');&lt;br /&gt;
});&lt;br /&gt;

Leave a Comment