I would like to create link of word(s) in post content (word(s) which is used as post tag of current post) to post tag URL. I created this, and it works, but only for one word (last tag) of post.

$post_content = get_the_content(); // Get post content
$search = array($tag->name);
$replace = array('<a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'" itemprop="url">'.$tag->name.'</a>');
$replacePairs = array_combine($search, $replace);
echo strtr($post_content, $replacePairs);

How to make it search for all words of tags (of current post) in post content and link that words to it's tag URLs?


You can use power of PHP. Explode the Words and Implode them. After exploding it you will get an array, with which you can loop through using foreach and call your function conditionally.

  • Could yoy please write that php code, to se it? Thanks. Dec 28 '16 at 8:39
  • @AdvancedSEO Please see the manual string replace and replace the matching tags with the warpped url you want to replace. Dec 28 '16 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.