How to show pdf in a new tab

Posted by: HAMZA ÖZAD

3rd January 2021, 6:05 am



3 Jan 2021
6:05 am

Hi, I want to show the downloads as pdf in a new tab. Do i have a chance to show pdf in new tab?

  • Richard Webster


    4 Jan 2021
    10:05 am

    Hi Hamza, you could force all free downloads to run in a new tab by using the following snippet. I recommend the Code Snippets plugin to create the snippet for the site.

    add_action('wp_footer', 'custom_always_open_free_downloads_in_new_tab');
    function custom_always_open_free_downloads_in_new_tab()
    	ob_start(); ?>
    	(function($) {
    		$(document).ready(function() {
    			$('form.somdn-download-form').each(function() {
    				$(this).attr('target', '_blank');
    	})( jQuery );
    	<?php $content = ob_get_clean();
    	echo $content;

    Last modified: 4th January 2021, 10:30 am by Richard Webster

This topic is closed to new replies.