Make WordPress More Link Open in a New Window

If you would like your WordPress ‘more’ tag link to open a new window, you can use this filter in your functions.php.

The ‘target=”_blank”‘ method has been deprecated in XHTML, so we are forced to use the onclick and onkeypress methods.


// More tag link open in new window
function more_tag_new_window($link) {
   preg_match('/^(.+)?<a (.*)$/',$link,$matches);
   if ($matches) {
      $link = $matches[1] . '<a '
         . '<a onclick="window.open(this.href); return false;" '
         . 'onkeypress="window.open(this.href); return false;" '
         . preg_replace('/#more-\d+/','',$matches[2]); // Remove the jump link
   }
   return $link;
}
add_filter('the_content_more_link','more_tag_new_window');

Leave a Reply

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

*