I would like to enclose the 2 first word of title inside a to get the following result:
TOP 5 of best photos
I tried using the code below, but it returns only the first word. How can i do to select 2 words?
Thank you
function add_label_to_post_title( $title = '' ) {
if(trim($title) != "")
{
$ARR_title = explode(" ", $title);
if(sizeof($ARR_title) > 1 )
{
$first_word = "<span>".$ARR_title['0']."</span> ";
unset($ARR_title['0']);
return $first_word. implode(" ", $ARR_title);
}
else
{
return "{$title}";
}
}
return $title;
} add_filter( 'the_title', 'add_label_to_post_title' );