Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Process "Lastname, Firstname" in post titles.
<?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;
}
@ms-studio

This comment has been minimized.

Copy link
Owner Author

ms-studio commented Feb 3, 2014

An updated version of this method: https://gist.github.com/ms-studio/3928828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.