函数文档

popuplinks()

💡 云策文档标注

概述

popuplinks() 是一个已弃用的 WordPress 函数,用于在内容中替换链接,使其在新标签页中打开。该函数从 WordPress 4.5.0 版本开始被标记为弃用,开发者应避免使用。

关键要点

  • 函数 popuplinks() 接受一个字符串参数 $text,返回过滤后的内容,其中链接被添加了在新标签页打开的属性。
  • 此函数已在 WordPress 4.5.0 版本中被弃用,建议使用替代方法或避免依赖此功能。
  • 函数内部使用 _deprecated_function() 标记弃用,并通过正则表达式处理链接。

代码示例

echo popuplinks('Please visit WordPress.comhttp://www.wordpress.com">WordPress.com;.');

注意事项

由于 popuplinks() 已弃用,开发者应检查代码并迁移到其他方法,以避免未来版本兼容性问题。相关函数 _deprecated_function() 可用于标记弃用。


📄 原文内容

Adds element attributes to open links in new tabs.

Parameters

$textstringrequired
Content to replace links to open in a new tab.

Return

string Content that has filtered links.

Source

function popuplinks( $text ) {
	_deprecated_function( __FUNCTION__, '4.5.0' );
	$text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text);
	return $text;
}

Changelog

Version Description
4.5.0 Deprecated.
0.71 Introduced.

User Contributed Notes

  1. Skip to note 4 content

    Basic usage:

    echo popuplinks( 'Please visit <a href="<a href="http://www.wordpress.com">WordPress.com</a&gt">http://www.wordpress.com">WordPress.com</a&gt<>;.' );

    Will output:
    [html]
    Please visit <a href="http://www.wordpress.com"; target=’_blank’ rel=’external’>WordPress.com
    [/html]