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:
- Adding a filter to the
wp_insert_post_data
. - Striping all link tags to prevent linking a word multiple times.
- Using the
explode
function to get an array of words inside the poem. - Add links to the words by using a simple
foreach
.
To generate your link you can follow one of these approches:
-
Creating a custom post type and use a plugin like
posts2posts
to connect your posts and finally generating the link usingthe_permalink
function. -
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 useadd_query_var
function and a hard-coded value of the page you’re putting your shortcode.