WordPress.org

Ready to get started?Download WordPress

Forums

Document Gallery
[resolved] Add Target Attribute to the Link tag (6 posts)

  1. joero4ri
    Member
    Posted 1 year ago #

    I think it would be nice to have an option for the target attribute of the resulting "a" tag. That way I can have all my documents open in a new window/tab.

    [dg target="_blank"] or something like that.

    Thanks, and keep up the good work.

    Joe

    http://wordpress.org/extend/plugins/document-gallery/

  2. Dan Rossiter
    Member
    Plugin Author

    Posted 1 year ago #

    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");

  3. Dan Rossiter
    Member
    Plugin Author

    Posted 1 year ago #

    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!
    -Dan

  4. pkacs
    Member
    Posted 1 year ago #

    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");

    FYI: http://www.notbybreadalone44.com/home/recipes-photos/

    Thanks in advance for any guidance you can offer.

    -Pat

  5. Dan Rossiter
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  6. kyao888
    Member
    Posted 6 months ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic