WordPress 获取文章中的第一个链接

在wordpress的世界里,奇葩到处都是.
最近在网上看到了这篇流弊的调用,记录一下以备不时之需

代码至Functions.php:

//Post Format - Link
function ct_url_grabber() {
 if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
 return false;
 
 return esc_url_raw( $matches[1] );
}

调用方式:

<?php echo ct_url_grabber(); ?>

小 虾

哦也,我是小虾

You may also like...