I'm having a recipe site where every post naturally contains ingredients. Every ingredient is a tag, and I would like to automatically link every ingredient so the user can click on it and see all recipes that uses that certain ingredient.

For this to be possible I guess I have to loop through every word in the post, then check if that word is equal to an existing tag, and wrap that word in a hyperlink. But I'm not sure that's the most efficient solution.

Do anyone of you have any suggestions here?

1 Answer 1


Are you sure you want to link every instance of each ingredient? As a user, I wouldn't mind if the ingredient list above the recipe had all its ingredients linked, but if the following instructions continued linking every ingredient I'd find that to be a lot of links I could accidentally tap on and lose the recipe.

If you're using the Block Editor, you could use the Tag List block to list the ingredients wherever in the recipe posts you need them. (Optionally you could add a block style to style them differently if you like.) If you're not using the Block Editor, you might want to set up a custom template for recipes, so that the template automatically creates an ingredients section between the recipe title and the rest of the content and outputs the tags there. If you're tagging anything besides ingredients, you could create a custom taxonomy so you're only outputting ingredients and not other unrelated tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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