Apr 1, 2005
Paladin

Open Links in New Window, WP Tutorial

I love WordPress. With that said, I’m sick of typing target=”_blank” on every link in a post. Here’s what I did to change things to that links inside of a post opened in a new window, but links to other portions of my site did not.

1. Global Change for links to open new window
File: index.php
Find: <head> tag
Add: <base target=”_blank”>

2. Article Titles
File: index.php
Find: <a> tag with “storytitle” class
Add: target=”_self” inside <a> tag

3. Category Links
File: /wp-includes/template-functions-category.php
Find: function the_category
Add in 3 spots: target=”_self” inside <a> tags

4. Comments Link
File: /wp-includes/template-functions-comment.php
Find: function comments_popup_link
Add: target=”_self” inside <a> tag

5. Calendar (sidebar)
File: /wp-includes/template-functions-general.php
Find: function get_calendar
Add in 3 spots: target=”_self” inside <a> tags

6. Category Links (sidebar)
File: /wp-includes/template-functions-category.php
Find: function list_cats
Add: target=”_self” inside <a> tag (near bottom inside Foreach loop)

7. Archive Links (sidebar)
File: /wp-includes/template-functions-general.php
Find: function get_archives_link
Add in 2 spots: target=”_self” inside <a> tags

8. Search Form (sidebar)
File: index.php
Find: <form> tag
Add: target=”_self” inside <form> tag

9. Misc. Links (sidebar) i.e. About Me
File: /index.php
Find: any instances
Add: target=”_self” inside <a> tags

10. Comments Form submit
File: /wp-comments.php
Find: <form> tag
Add: add target=”_self” attribute

Let me know if I’ve missed something, and I’ll update this post.

Update 8/11: As of today, I’ve taken this code out because I’m just annoyed. Ha!

11 Comments

  • The thing that you missed is that having links open in a new window is actually somewhat annoying. If the user wanted a new window he would specifically ask
    for one. With tabbed browsing it’s almost pointless, because the user would rather have a new tab anyway.

  • Good point. I just like it that way and am forcing my preferences on everyone else. ;^)

    I always think it’s frustrating to click on a link that doesn’t open in a new window and have to click back to read the rest of the story. But you have a good point.

  • Will go with Paladin on this one. Then again it is a matter of preference.
    I prefer opening external links in new pages.

  • But it breaks the valid XHTML.

  • Or it should from my understanding anyways (sorry for the double comment).

  • The target=”_blank” attribute is certainly not compliant with the xhtml 1.0 strict standard – if you’re concerned about it you should mark the page as transitional xhtml once you’ve introduced these elements

  • I just wanted to state my agreement with “wow just wow”. No offense to you personally, but when I saw this plugin announced, it made me cringe. :)

    A normal link can always be opened in a new window, but a target=”_blank” link cannot (normally) be opened in the same window.

    Thankfully, Firefox let’s me disable the annoying target=”_blank” behavior.

    Oh well, to each his or her own, I suppose. :)

  • BTW, I have written a similar hack which requires the editting of only quicktags.js file and provides better flexibility in adding the target attribute.
    Please check it out here.

  • Thanks for the hack… When I’m the one that browses I use FireFox and tabed navigation, but unfortunatelly most users I know have no idea about computers, navigation and other subjects, so they limit their experience to what is given in the box when they buy the computer (i.e. Windows and IE) and sometimes the experience is frustrating for them.

    For me the hack using .js was not valid, I try not to use .js nor cookies or plugins… just plain HTML in the output :)

  • [...] Posted by Ajay under Blogging  Having read the tutorial by 21st Century Paladin on Opening Links in New Windows, I dug up an old post of mine in which I had editted the qui [...]

  • I found this actually rather good for my blog as I want to retain the user to read the news and topics I post while still being able to reference outside material. I personally prefer the functionality over the xhtml compliance and outside preferences.

    Feel free to visit my Ironvine Search Marketing

Leave a comment

Categories

Archives

Add to Technorati Favorites