Split a Post Title in Half

CSS Tricks,Wordpress How-To's

In this post I’ll explain how to take a WordPress page or post title, split it in half and style each half differently.The first thing we’ll need to do is get the title and turn it in to a variable. Then we need to explode that variable using a space as the break point.split title in half Then we can count the total words in the title and divide that number by 2 to figure out where to split it. After that we create a 2 separate strings and can use those variables however we like.

$title = get_the_title($ID);
$word = explode(' ', $title);
$totalwords = count($word);
$halfnumber = $totalwords / 2;
$string1 = implode(' ', array_slice($word, 0, $halfnumber));
$string2 = implode(' ', array_slice($word, $halfnumber));


What's the Buzz?

Andy is a true top notch programmer with a great eye for design, style and balance. When I out source web development projects, I look for qualified and competent programmers that can understand the big picture, add value throughout entire process, and pays close attention to the details – Andy fits the bill.

Andy is well-versed in web development using various programming languages and CMS platforms. Andy is able to deliver a flawless website based on the creative vision and project requirements. He is able to do it on time and on budget.

I highly recommended Andy as a web developer and give him four stars on his professionalism.

- John LeDonne
LeDonne Creative