Last active
November 24, 2020 10:30
-
-
Save ms-studio/8793349 to your computer and use it in GitHub Desktop.
Process "Lastname, Firstname" in post titles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Processing "Last name, First name" pairs | |
* | |
* @param string $nom_prenom : The original post title ("Wilde, Oscar"). | |
* | |
* @return string : The human-readable title ("Oscar Wilde"). | |
* | |
* Usage in theme: | |
* $post_title = firstname_lastname(get_the_title()); | |
* | |
*/ | |
function firstname_lastname($post_title) { | |
$pos = strpos($post_title, ","); | |
if ($pos === false) { | |
// nothing to do. | |
} else { | |
$fir = explode( ",", $post_title ); | |
unset( $fir[0] ); | |
$end = ltrim( implode( ",", $fir ) ); | |
$first_name = substr($post_title, 0, $pos); | |
$pos++; | |
$post_title = substr($post_title, $pos) . ' ' . $first_name; | |
} | |
return $post_title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An updated version of this method: https://gist.github.com/ms-studio/3928828