I would like to filter the post and page content to append html tags to specific content prior to saving the content to the database.
For example, given a keyword phrase “Red Yoga Mats”, I would like to scan the page/post content and replace the first instance of “Red Yoga Mats” with <b>Red Yoga Mats</b> and replace the second instance with <i>Red Yoga Mats</i> and the 3rd instance with <u>Red Yoga Mats</u>.
How difficult would this be?
(The phrase “Red Yoga Mats” is arbitrary. I’d like to place this as a dynamic variable that I would pass to the filter function that does the content append)
You could use a filter on
the_content
for this.it would be more easy if you will make this change in moment, when post is not saved, but displayed (in this case use the_content filter hack) but if you really want to make changes when post is saved, use action hack save_post. some pseudo code: