How to auto insert target=”blank” in wordpress!

Hi,
So all of you must have used the link button in the WP editor to create links. Now the default link button makes your links open in the same tab. If you want to make your links open in a new tab, you have to add target=”_blank” to your a tag.

Now to do that manually everytime or use a text editor to manually edit (Ctrl+F, Ctrl+H) or whatever to search replace and add target=”_blank” could be a tedious job! Why do it when you can edit one file and automate it forever.

The file in question is quicktags.js and resides in “wp-includes/js” folder.

Open the file in a text editor and search for “function” till you come across “function edInsertLink”. This is the function responsible for inserting links to your posts.

Edit this function so that the corresponding part now reads as

edButtons[c].tagStart=’<a href=”‘+a+’” target=”_blank”>’

and save.
There you go.
Now your links will have target=”blank” as a part of them.

Or you can just download the file from here and save it in your wp-include/js/ folder.
cheers!

the anAlyst

4 thoughts on “How to auto insert target=”blank” in wordpress!

  1. Hi Snehan,

    How exactly are you generating the dynamic links? Are you using any existing plugin? Let me know which plugin you are using, then I can try to help.
    Easy way to trouble shoot, go through the code of your plugin and look for “blank” in there. You will need to remove one or more of the blank or conditions.

    Hope to help.

    regards
    Anshu Prateek

  2. Hi Anshu,

    Thanks for willing to help :) . but i was able to figure it out after sometime. I had actually written the code myself manually and was not using a plugin. But the page permalink format was causing the links to behave as external links and _blank was added. So i had to do some changes to my code for wordpress to understand my link as an internal link.

    Thanks again :)

    Regards
    Snehan Solomon

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>