I am not a PHP expert or even intermediate by any means.
I am trying to assign a couple of HTML spans to a post title in a WordPress page.php
One span will be added to the first word of the title and the other span should apply to the rest of the rest of the title.
I started with this code, which got me half way there:
<?php
$words = explode(' ', the_title('', '', false));
$words[0] = '<span class="bold-caption">'.$words[0].'</span>';
$title = implode(' ', $words);
echo $title;
?>
As you can see the first Key of the array has the first spam assigned.
I can’t manage to assign the other to the rest of the title.
How can I accomplish this? Thank you in advance.
You’re close…I’d
unset()
the first item after adding aspan
around it,implode()
the rest, and concatenate: