WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Force target="_blank" (8 posts)

  1. Shyzer
    Member
    Posted 4 years ago #

    Is there any way to edit one of the core WP files so that every link created with the link quicktag button includes target="_blank" and rel="nofollow"? Or better yet, is there a way to make a popup box appear after the link popup box where you could check the two boxes if you wanted those two attributes?

    I know I used to be able to edit quicktags.js back in the day and make this work, but that was pre-2.0 WP. Now, I'm unable to get it to work.

    I run a blog with multiple authors and they always forget to add these two things to their links, so I have to go behind them and manually edit them in. It'd be a lot easier for me if I could make this happen automatically.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Quicktag Extender

    Although I have to say that I think links that spawn new windows without warning the user are evil.

  3. Shyzer
    Member
    Posted 4 years ago #

    Esmi, in most cases, I would agree. However I've done tons of research / polls with my users and they overwhelmingly want links to open in a new window. It has to do with my site material, where each post can have dozens of links to different coupons and freebies.

    Adding a new button would be an option, but is there a way to edit the pre-existing link button so that it automatically includes the two attributes? I used to do that with an older version of WordPress, but the newer version of quicktags.js is all jumbled into one giant line instead of broken up.

  4. syncbox
    Member
    Posted 4 years ago #

    You can always edit the quicktags.dev.js version and then upload it to the server with the quicktags.js name.

  5. syncbox
    Member
    Posted 4 years ago #

    Or add a new quicktag tool button that can be used to insert a new window attribute on a per link basis...

    Something like:

    edButtons[edButtons.length] =
    new edButton('ed_target'
    ,'Open in New Window'
    ,' onclick="target=\'_blank\'"'
    ,''
    ,'r'
    ,-1
    ); // special case

    so that after you create your link in your post or page, you can insert the cursor after the href and click the new window button to insert the javascript onclick function

  6. Shyzer
    Member
    Posted 4 years ago #

    I didn't realize the quicktags.dev.js file as the same as quicktags.js. Editing that and then uploading it to the server as quicktags makes perfect sense. Thanks for pointing that out.

    I'd rather use the quicktag tool button that you suggested as a backup option. My main goal would be to edit the pre-existing link quicktag button. Does anybody know while line of code I would edit? There are four instances of "href" in the quicktags file, but I'm not sure which one to add the two attributes to.

  7. Shyzer
    Member
    Posted 4 years ago #

    Just for the record, I was able to get what I wanted by changing line 369 to

    edButtons[i].tagStart = '<a href="' + URL + '" target="_blank" rel="nofollow">';

    Now, when I add a link, the two attributes I wanted are inserted. I'll have to update the file every time a new WordPress comes out, but that's fine as I really didn't want to run yet another plugin.

  8. syncbox
    Member
    Posted 4 years ago #

    That's great to know...

    You should mark this topic resolved if it is.

Topic Closed

This topic has been closed to new replies.

About this Topic