How to generate/create link automatically on every word of post in wordpress

I don’t know the scale of your project, my solution will help you to get around it quickly, but it’s inefficient when it comes to larger scaled projects.

The easy way

You can add a filter to the_content filter and finally link every word inside of the content to the search page of that specified word.

The Hard Way

This is way much better than the first solution when it comes to scale and efficiency.

By assuming that your content is in English and are divided using some character, the general process would be:

  1. Adding a filter to the wp_insert_post_data.
  2. Striping all link tags to prevent linking a word multiple times.
  3. Using the explode function to get an array of words inside the poem.
  4. Add links to the words by using a simple foreach.

To generate your link you can follow one of these approches:

  1. Creating a custom post type and use a plugin like posts2posts to connect your posts and finally generating the link using the_permalink function.

  2. Creating a custom table for keeping track of words and the connected posts.

    For the second approach, you have to add a query var by adding a filter to query_vars filter, create a custom shortcode to display your data and finally to generate the links you have to use add_query_var function and a hard-coded value of the page you’re putting your shortcode.