php - Tackle specific Array Key -
i not php expert or intermediate means.
i trying assign couple of html spans post title in wordpress page.php
one span added first word of title , other span should apply rest of rest of title. started code, 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 can see first key of array has first spam assigned.
i can't manage assign other rest of title.
how can accomplish this? thank in advance.
you're close...i'd unset()
first item after adding span
around it, implode()
rest, , concatenate:
<?php // split title array of words $words = explode(' ', get_the_title()); // create new title, first word bolded $newtitle = '<span class="bold-caption">' . $words[0] . '</span>'; // remove first word array of title words unset($words[0]); // concatenate remaining words (in new span) first word $newtitle .= '<span>' . implode(' ', $words) . '</span>'; echo $newtitle; ?>
Comments
Post a Comment