auto link word link in content

i use this code for auto link word in content<?php function link_words($content){$words=array('test1',

i use this code for auto link word in content

<?php function link_words($content){
$words=array(
    'test1',
    'test2',
    'test3'
);
$links=array(
    '<a href="/tag/test1/" rel="nofollow">test1</a>',
    '<a href="/tag/test2/" rel="nofollow">test2</a>',
    '<a href="/tag/test3/" rel="nofollow">test3</a>'
);
$content = str_replace($words,$links,$content);return $content;}
add_filter('the_content','link_words');
add_filter('the_excerpt','link_words'); ?>

but upper code have one problem, so changed and linked any word (images alt , ...)
i want only word between <p></p>

i want finally link any word in content to tags and categories

i use this code for auto link word in content

<?php function link_words($content){
$words=array(
    'test1',
    'test2',
    'test3'
);
$links=array(
    '<a href="/tag/test1/" rel="nofollow">test1</a>',
    '<a href="/tag/test2/" rel="nofollow">test2</a>',
    '<a href="/tag/test3/" rel="nofollow">test3</a>'
);
$content = str_replace($words,$links,$content);return $content;}
add_filter('the_content','link_words');
add_filter('the_excerpt','link_words'); ?>

but upper code have one problem, so changed and linked any word (images alt , ...)
i want only word between <p></p>

i want finally link any word in content to tags and categories

Share Improve this question edited Sep 21, 2019 at 13:05 user168547 asked Sep 21, 2019 at 12:46 user168547user168547 52 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

If I understand correctly ... first of all you need to match everything inside paragraphs using regex.

$content = "<p>some text which includes test1 and test2 etc</p>";
preg_match_all("/<\s*p[^>]*>([^<]*)<\s*\/\s*p\s*>/", $content);

then you can use your code.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745140622a4613413.html

相关推荐

  • auto link word link in content

    i use this code for auto link word in content<?php function link_words($content){$words=array('test1',

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信