【发布时间】:2018-06-27 21:30:32
【问题描述】:
请我想实现从下面的代码中排除<h2>, <a> and <img> html 标记的目标。我正在尝试用帖子内容中的链接替换标签关键字,并排除标签链接影响我上面列出的html标签。
function link_words( $text ) {
$tags = get_tags();
if ( $tags ) {
foreach ( $tags as $tag ) {
$from = '/' . $tag->name . '/';
$to = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $tag ) ), esc_html( $tag->name ) );
$text = preg_replace($from, $to , $text, 2);
}
}
return $text;
}
add_filter( 'the_content', 'link_words' );
请在房子里的大师,有什么出路吗?我是 wp 函数编码的新手。
【问题讨论】:
标签: wordpress