让WordPress文章内链接在新窗口打开的方法

  • 时间:2020-05-17 12:22:02
  • 分类:网络文摘
  • 阅读:123 次

在使用wordpress进行创作的时候,经常会在文章中留下许多外部链接,如果当时忘了设置链接的打开方式,默认会在当前窗口打开链接,这样做的后果就是用户阅读时点击链接会跳出你的站点。如果文章中这样的链接很多,对网站的用户黏度会产生不利影响。想要手动更改这些链接的打开方式显然也不现实,这里介绍一个wordpress技巧,使用简单的一段代码就可以将这些链接统一更改为在新窗口打开。

将下面的代码添加到wordpress主题的 functions.php 模板文件中最后一个 ?> 前即可。

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

代码来自:http://www.aips.me/new-window-opens-wordpress-article-all-links.html

推荐阅读:
Bruteforce or Line Sweep Algorithms to Remove Covered Intervals  Microbit Programming: The Development of a Snake Eating Apple Ga  Compute the Angle of the Hour and Minute Hand on a Clock  How to Convert Binary Number in a Linked List to Integer?  The Permutation Iterator in Python  Compute the Indices of the Target Element in Array/List using Py  5 Cognitive Biases You Can Use to Boost E-Commerce Conversions  Important SEO Tips for E-commerce That You Cannot Disregard  5 Effective Ways to Improve Blog Conversion Rate  7 Reasons Blogging is Essential for Law Firms 
评论列表
添加评论