Support » Plugin: Document Gallery » Add Target Attribute to the Link tag

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dan Rossiter


    Hey joero4ri,

    Thanks for the suggestion! I actually think I can do you one better. I will probably include an option to include an arbitrary list of attributes to include within the link.

    I need to work out exactly how I want to implement it, but should have something like that out within the next few weeks.

    Edit: After first writing the answer above, I reconsidered. Though I may still add this in the future if there is enough demand, there are JavaScript-based solutions that will achieve what you want without putting additional strain on the server. The below solution, which is actually in jQuery, but could easily be implemented in plain JS also, would produce the results you’re looking for while putting no added strain on the server (I would like to not decrease speed in generating the document gallery). It could also be modified to do anything else you may want with all links within a document gallery.

    $(".document-icon > a").attr("target","_blank");

    Plugin Author Dan Rossiter


    Hi joero4ri,

    If that solution doesn’t meet your needs, I’ve also just pushed out version 1.3 which supports filtering the document icon, including the anchor tag you want to add a target to.

    If you want to look into that option, you can see the documentation for the filter on the Installation tab.

    Let me know if you run into anything else!

    Very new to WordPress & know nothing about jQuery or JS.
    Where do I insert this to get my documents to open up in a new tab?
    $(“.document-icon > a”).attr(“target”,”_blank”);


    Thanks in advance for any guidance you can offer.


    Plugin Author Dan Rossiter


    Hi pkacs,

    I actually made a mistake in that post. Since WordPress loads jQuery in no conflict mode, you’re actually going to want to write this:

    jQuery('.document-icon > a').attr('target', '_blank');

    Anyway, there are a few ways you can get that into your pages. The easiest is probably to add a little function to functions.php in your theme. The only thing is, if you aren’t using your own theme then it will be overwritten when you update your theme. Themes tend to not get a large number of updates though, so let’s assume that’s not an issue.

    You would want something like this (untested) function/action hook combinaion:

    function dg_target_blank(){ ?>
      jQuery.ready( function(){
        jQuery('.document-icon > a').attr('target', '_blank');
    <?php }
    add_action( 'wp_print_footer_scripts', 'dg_target_blank' );

    Like I said, haven’t tested this function so you may need to hack around with it, but it should be close to what you need.

    Hello. Reopening this support. How can I open the uploaded document in a separate window? I have limited resources on coding. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add Target Attribute to the Link tag’ is closed to new replies.