Home › Forums › Back End › Adding span to WordPress widget title › Reply To: Adding span to WordPress widget title
January 6, 2016 at 12:05 am
#236433
Participant
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:
<?php
$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 span
s by just moving where in the output string you concatenate the span
:
echo '<span>' . array_shift($string) . '</span> ' . implode(" ", $string);