0

I'm currently designing a theme using Underscores and I want to do something like this with the site's title:

Thisisthetitle

So the title is all one word and the last five characters are different to the rest. I am currently using the bloginfo function to display the title and I can't figure out a way to split it so I can style each section of the title differently.

I have tried creating a function to splice it, but to no avail.

  • By title do you just mean you're outputting the site title in the header, like the words "WordPress development" at the top left of this page? Or do you mean the HTML <title>? In either case you should be able to use substr twice - once to grab everything but the last 5 characters, again to grab the last 5, then add whatever <span> etc. tags you need. – WebElaine Mar 24 '17 at 13:42
  • I want the output to be the actual site's title - not the HTML <title> tag - with two different styles applied to it. – Dan Cross Mar 24 '17 at 13:49
1

Figured it out!

function split_title($title) {
$title = get_bloginfo('name');
$word = substr($title, 0 , 5);
$press = substr($title, 5);

$html = "{$word}<span class='bold'>{$press}</span>";

return $html;
}

And then <?php echo split_title($title); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.