I am working on a poetry site and I am new to wordpress. I want to publish poems of various authors on my site. What i want is that when i publish a post, a link/onclick event on every word of post may be generated automatically in background. When a user click on any word of post, he may be directed to a new page containing poems with that similar word. Any help or direction will be appreciated a lot.

1 Answer 1


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.

  • Thanks a lot man, I will definitely give it a try. Actually I am working on a poetry site in urdu language. Sep 10, 2018 at 12:13

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.