admin管理员组文章数量:1130349
I am trying to replace tag keyword with link within post content. below is my code but it is making the whole content to disappear, I dont really know where i am getting it wrong.
function link_words( $text ) {
$tags = get_tags();
if ( is_single() && in_category( 'Tutorial' )) {
foreach ( $tags as $tag ) {
$from = '!<h2>[^<>]*<\/h2>(*SKIP)(*F)|<b>[^<>]*<\/b>(*SKIP)(*F)|<a\b[^>]*>.*?</a>(*SKIP)(*F)|(\b'.$tag->name.'\b)(?=[^>]*(?:<|$))!';
$to = sprintf( ' <a href="%s">%s</a> ', esc_url( get_term_link( $tag ) ), esc_html( $tag->name ) );
$text = preg_replace($from, $to , $text, 5);
}
}
return $text;
}
add_filter( 'the_content', 'link_words' );
Please Gurus in the house help me out, I am new to coding wp funtions
I am trying to replace tag keyword with link within post content. below is my code but it is making the whole content to disappear, I dont really know where i am getting it wrong.
function link_words( $text ) {
$tags = get_tags();
if ( is_single() && in_category( 'Tutorial' )) {
foreach ( $tags as $tag ) {
$from = '!<h2>[^<>]*<\/h2>(*SKIP)(*F)|<b>[^<>]*<\/b>(*SKIP)(*F)|<a\b[^>]*>.*?</a>(*SKIP)(*F)|(\b'.$tag->name.'\b)(?=[^>]*(?:<|$))!';
$to = sprintf( ' <a href="%s">%s</a> ', esc_url( get_term_link( $tag ) ), esc_html( $tag->name ) );
$text = preg_replace($from, $to , $text, 5);
}
}
return $text;
}
add_filter( 'the_content', 'link_words' );
Please Gurus in the house help me out, I am new to coding wp funtions
本文标签: functionsReplace Tag Keyword With Link Within Post Content
版权声明:本文标题:functions - Replace Tag Keyword With Link Within Post Content 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749176448a2327875.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论