How to make all existing internal links open in same window?

Sutra

Breathe the body deep
BuSo Pro
Joined
Oct 28, 2015
Messages
616
Likes
592
Degree
2
#1
Back when my main monetization method was ad views I made all my internal and external links open in a new window. Since then I've kept it that way with new articles to stay consistent. However, it would be a better user experience to make all internal links open in same window.

I found some info on doing this via javascript/plugin here and here, however, I would like to do this without js or plugin if possible (would prefer not to add more overhead to the processes).

To sum up: I would like to make all existing internal links open in same window, BUT keep all existing external links opening in new window. How can do I do this?
 

Ryuzaki

女性以上のお金
Staff member
BuSo Pro
Digital Strategist
Joined
Sep 3, 2014
Messages
3,103
Likes
5,672
Degree
7
#2
@Sutra, if this is Wordpress (or any other CMS), you can determine the structure of the links and make sure they're all the same and run a MySQL query to remove the target="_blank" from the ones that are internal. It'll probably require some Regex, which I suck at or I'd say more.

If it is Wordpress, you're already loading jQuery and Javascript is native to browser's, so it wouldn't be a huge deal to drop some inline code in the footer. But I agree, I'd rather fix it at the database level.
 

SmokeTree

Developer/Linux Consultant
BuSo Pro
Digital Strategist
Joined
Sep 23, 2014
Messages
195
Likes
338
Degree
1
#3
What I did to address this for Sutra was write a Ruby script using nokogiri (HTML parser) that read the wp_posts table and parsed the HTML in the post_content field. I iterated over all the links and created a simple regex to see if the link was for the domain of his site (Internal Links) and if so, change the target attribute to "_self" (which is default and not needed but easier to change than to delete the attribute) otherwise change target to "_blank".

Now if you're using "Thrive Architect", it gets a bit more involved. In that case, you have to read the wp_postmeta table and query the meta_key field for values such as "tve_save_post" and "tve_updated_post" and do the same thing as above. There's one catch though. In the thrive editor, when one embeds "Wordpress Content", it sometimes renders the HTML in a raw format and something not parsable by nokogiri so I couldn't really get to those links without getting caught in regex hell. This only affected a few posts in this case so those few posts will have to be edited manually, otherwise the vast majority of the links were successfully changed and the desired result was achieved without requiring a plugin.