How to Avoid Losing Visitors Due to Comment Links

Note: The code in this arti­cle was updat­ed and test­ed to work as of 2015-09-01.

If you run a Word­Press-pow­ered web­site, ask your­self, how many users leave your site by fol­low­ing the links left by com­menters? The answer will no doubt vary great­ly site to site, but if your users are leav­ing your site pre­ma­ture­ly and for­get­ting to come back, then you need to improve that sit­u­a­tion straightaway.

And it’s easy to do! What we’ll do is add a small snip­pet of code to your site which will alter the links to instead open in a new tab (or win­dow, if tabs are unavail­able), ensur­ing your site remains open in the user’s brows­er. Links which point to the cur­rent site’s address (as deter­mined by home_url() will not open a new tab). 

Sim­ply open your The­sis 1.8.x custom_functions.php or your site’s func­tion­al­i­ty plu­g­in and paste in the fol­low­ing bit of code:

 * Comment author links open in new windows
function custom_pop_open_external_commenter_links ( $link ) {
	if ( ! strstr( $link, get_home_url() ) ) {
		return str_replace( 'rel=\'', 'target=\'_blank\' rel=\'', $link );
	} else {
		return $link;
add_filter( 'get_comment_author_link', 'custom_pop_open_external_commenter_links' );

If you want all com­ment author links to open in new win­dows, sim­pli­fy the code to this:

 * Comment author links open in new windows
function custom_pop_open_external_commenter_links ( $link ) {
	return str_replace( 'rel=\'', 'target=\'_blank\' rel=\'', $link );
add_filter( 'get_comment_author_link', 'custom_pop_open_external_commenter_links' );

Also, I should point out that this code inval­i­dates The­sis’ XHTML strict markup due to that par­tic­u­lar stan­dard not rec­og­niz­ing the target attribute.

Learn how to con­vert your The­sis site from XHTML Strict to HTML5!

Tab for a Cause

Obvi­ous­ly, keep­ing vis­i­tors on your site is a pos­i­tive thing, but all of this talk about tabs reminds me of an amaz­ing way to spread pos­i­tiv­i­ty: <a href=”/get-tfac/”>Tab for a Cause</a>!

Tab for a Cause is a brows­er exten­sion which turns the “new tab” place­hold­er page into a won­der­ful­ly sim­ple tool to raise mon­ey for char­i­ties, and all you have to do to con­tribute is keep open­ing new tabs like you would be anyway!

Do your part to make the world a slight­ly bet­ter place.<a href=”/get-tfac/”>Get Tab for a Cause</a> and keep on press­ing that “new tab” button!

17 thoughts on “How to Avoid Losing Visitors Due to Comment Links”

  1. Maybe it’s just me, but I’d rather have the com­ments load in a pop-up box…that way as soon as they’re done with the com­ments, they’re back on my site.

    1. There is a com­pelling case to made for using Word­Press’ pop­up com­ments fea­ture; how­ev­er, for most peo­ple (myself includ­ed), pop­up box­es are annoy­ing and may even be blocked by browsers.

      Open­ing links in new win­dows at all isn’t an ide­al solu­tion, at least not until browsers give users the option to dis­able such behav­ior, but it’s far more accept­ed than pop­up windows.

  2. Had anoth­er ques­tion Rick(and this kin­da freaked me out in a good way).

    How do you get the “Speak Up, XYZ” in the com­ment intro? I noticed it on the Timthumb post and was total­ly blown away!! Adds a whole new spin to the per­son­al­i­sa­tion angle…

    Are you using cookies/​custom php? How can one repli­cate this?

    1. You’re the first per­son to com­ment on that! And you’re right, it is a com­bi­na­tion of Word­Press cook­ies & cus­tom code. The exact code I’m using fol­lows; sim­ply drop it into custom_functions.php. A prop­er tuto­r­i­al on this code will show up some­time in the future, i’m sure.

       * Customizes the text introduction to the list of comments
      function custom_comments_intro( $intro ) {
      	if( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) )
      		$commenter = ', ' . $_COOKIE[ 'comment_author_' . COOKIEHASH ];
      		$commenter = '';
      	$intro = str_replace( ' comment', ' voice', $intro );
      	$intro = str_replace( '&#8230; read it below or', ' in the conversation.', $intro );
      	$intro = str_replace( '&#8230; read them below or', ' in the conversation.', $intro );
      	$intro = str_replace( 'add one', 'Speak up' . $commenter . '!', $intro );
      	$intro = str_replace( ' trackback', ' linkback', $intro );
      	return $intro;
      add_filter( 'thesis_comments_intro', 'custom_comments_intro' );
      1. Haven’t seen this on any oth­er site. Peri­od. Seen some gor­geous CSS work but the PHP is pret­ty vanilla.

        Stuff like this blows me away…

        Love your daily/​weekly The­sis snippets…

        1. Style isn’t my strong suit at all. Code tweaks, how­ev­er… Well, I can rock those. Keep your eyes on my Word­Press direc­to­ry for all my lat­est tuto­ri­als. Not much there yet, but i’m going to keep work­ing on it! (It’s all tar­get­ed to The­sis users, of course.)

    1. A styles ques­tion? Hmm… That’s cru­el, man. I know how to turn on post for­mats in The­sis — link, quote, etc. — but styling them well is not some­thing i’ve yet to pull off, which is why i don’t use them here.

                1. There are a cou­ple of things which could be wrong. Make sure you’re using the lat­est ver­sion of Word­Press, and make sure the exter­nal link box isn’t hid­den in “Screen Options” at the top of the post. Also, the box will only appear for sin­gle post adding/​editing, not for Pages.

                  When it works, the box should appear just above the cus­tom fields meta box, but it can be dragged to any oth­er location.

                  1. Hous­ton, we have liftoff!! I can’t thank you enough for this Rick…it must have tak­en you ages to bang it out. Works like a charm…I can see the meta box now. Ques­tion: would this also hold good for teasers if I knock out the is_single?

                    1. Pos­si­bly. With­out look­ing at the code, i’d sus­pect that you’d need anoth­er con­di­tion­al in there to detect whether the head­er is for a teas­er or not (unsure if the markup for teas­er head­lines is the same). You could cer­tain­ly try it; worst case sce­nario, you just have to add the con­di­tion­al back in.

Leave a Reply to Rick Beckman Cancel Reply

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

Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

Comments must be made in accordance with the comment policy. This site uses Akismet to reduce spam; learn how your comment data is processed.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

A Salted Faith
%d bloggers like this: