Return to Snippet

Revision: 64996
at October 13, 2013 02:09 by FlashBuddy


Initial Code
// split name

if (!function_exists('the_title')) {
	function the_title($name) {
		if($name!='') { return get_the_title($name); }
		else return false;
	}
}

if (!function_exists('split_name')) {
	function split_name($name) {
		if(strpos($name,' ')!==FALSE) {
			$name_arr = explode(' ',$name);
			if(count($name_arr)==2) { return $name_arr[0].'<br/>'.$name_arr[1]; }	
			elseif(count($name_arr)==3) { return $name_arr[0].' '.$name_arr[1].'<br/>'.$name_arr[2]; }
			else { return $name; }	
		} else { return $name; }
	}
}

// Template usage -  echo split_name(get_the_title());

Initial URL
http://flashalexander.com/split-name-wordpress-function/

Initial Description
I ran into a situation where I needed to break names into two lines. I tried css word-break: unsuccessfully, then came up with this function.

Initial Title
WordPress Function Split Name  onto Two Lines (or any two strings/titles)

Initial Tags

                                

Initial Language
PHP