One-to-many times, you wish to break the name into two lines. Well, to achieve the same, all you have to do is to use the following snippet and you are done.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // 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()); |
Snippet Source/Credit: FlashAlexander