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.
Source
function popuplinks( $text ) {
_deprecated_function( __FUNCTION__, '4.5.0' );
$text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text);
return $text;
}
Skip to note 3 content
Codex
echo popuplinks('Please visit <a href="<a href="http://www.wordpress.com">WordPress.com</a>">http://www.wordpress.com">WordPress.com</a><>;.');will output
Please visit <a href="http://www.wordpress.com" rel="nofollow">WordPress.com</a>Skip to note 4 content
Drew Jaynes
Basic usage:
echo popuplinks( 'Please visit <a href="<a href="http://www.wordpress.com">WordPress.com</a>">http://www.wordpress.com">WordPress.com</a><>;.' );Will output:
[html]
Please visit <a href="http://www.wordpress.com"; target=’_blank’ rel=’external’>WordPress.com
[/html]