How to show pdf in a new tab

Posted by: HAMZA ÖZAD

3rd January 2021, 6:05 am

HAMZA ÖZAD

@hamzaozad

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?

  • Developer
    Richard Webster

    @rwebster

    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(); ?>
    
    	<script>
    	(function($) {
    		$(document).ready(function() {
    			$('form.somdn-download-form').each(function() {
    				$(this).attr('target', '_blank');
    			});
    		});
    	})( jQuery );
    	</script>
    
    	<?php $content = ob_get_clean();
    
    	echo $content;
    }

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