The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Adding span to WordPress widget title Reply To: Adding span to WordPress widget title

Ilan Firsov

Ideally I would like to add the span to everything but the first word but I can write my CSS code to work the other way.

You can do something like this:

$string = "this is a test !";
$string = explode(" ", $string);
echo array_shift($string) . ' <span>' . implode(" ", $string) . '</span>';
// returns:
// this <span>is a test !</span>

array_shift removes the first element from the array and returns it. Here I used it to isolate the first word from the rest of the ‘exploded’ string.
This is easily adapted to wrap the first word with the spans by just moving where in the output string you concatenate the span:

echo '<span>' . array_shift($string) . '</span> ' . implode(" ", $string);