Generate keyword automaticly from post titles

For example I have title “The Battleship Trailer”
so it will generate keyword like this
“best , player, of, the, world”
how can i do it ?

I want to apear in html like this…

Read More
First:The
Second:Battleship
Third:Trailer

<meta name="keywords" content="<FirstWord>,<second>,<third>"/> 

More exactly i want to split the title in words.

I use WordPress

Related posts

Leave a Reply

3 comments

  1. echo '<meta name="keywords" content="'.implode(',', explode(' ', $string)).'"/>';
    

    This would join the words separated by a space in $string with a comma. Obviously replace $string the proper variable.

  2. It might be better to get the post’s slug. That will sanitize and strip out any shorter words that won’t be of any value to search engines. Then explode and implode with PHP…

    Here how:

     // Get the global post variable (inside or outside the loop)
     global $post;
    
     // Seperate title slug by dashes into array
     $the_slug_into_array = explode('-', $post->post_name);
    
     // Convert array back into a string with comma separation
     $the_keywords = implode(',', $the_slug_into_array );
    
     // Echo out the string of terms from the title
     echo $the_keywords;
    

    Let me know if this worked for you…