• How can i show the number of times a keyword that is typed in is being shown on each page of the results in the title of each result?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter emergencyx

    (@emergencyx)

    nevermind i figured it out using chatgpt. This thing is awesome . code is below:

    function count_keywords_in_content($title, $id) {
    if (is_search()) {
    global $wp_query;
    $keyword = $wp_query->query[‘s’];
    $content = strip_tags(get_post_field(‘post_content’, $id));
    $count = substr_count(strtolower($content), strtolower($keyword)) + substr_count(strtolower(get_post_field(‘post_title’, $id)), strtolower($keyword));
    if ($count && strpos($title, ” Times this keyword is shown”) === false) {
    $title = $title . ” (” . $count . ” Times this keyword is shown)”;
    }
    }
    return $title;
    }
    add_filter(‘the_title’, ‘count_keywords_in_content’, 10, 2);

    • This reply was modified 1 year, 10 months ago by emergencyx.
    Plugin Author dFactory

    (@dfactory)

    Nice. But how do you store that? In post_views table?

    Thread Starter emergencyx

    (@emergencyx)

    Save that code in the functions.php file of your wordpress.

    Hello, this is interesting and I installed it on my site. I don’t really understand what this script should do, (the translation is bad). Do you have an example link so I can see what it does? Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can i show the number of a times a keyword is shown in each page’ is closed to new replies.