WordPress automatically adds target="blank" attribute to the outer chain

 Watson Blog August 16, 2017 15:43:17 WordPress comment three hundred and eighty-four Reading mode

WordPress automatically adds target="blank" attribute to the outer chain

WordPress自动给外链添加target=“blank”属性

Method 1:

Add the following code directly to the functions.php Medium

  1. function autoblank( $text ) {
  2. $return = str_replace ('<a', '<a?target= "_blank" ', $text );
  3. return $return ;
  4. }
  5. add_filter('the_content', 'autoblank');

Method 2:

It is implemented by JQ code and can be directly added to the main JS. At least I tried it this way. If you have problems after trying, you can leave a message for feedback.

  1. var ? root?=?location.protocol?+?'//'?+?location.host;
  2. $('a').not(':contains(root)').click( function (){
  3. this .target?=? "_blank" ;
  4. });

In fact, another way is to choose to open in a new window when adding links. This function can also be achieved. If there are few articles, you can still use code.

 Watson Blog
  • This article is written by Published on August 16, 2017 15:43:17
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/193.html

Comment