Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
Created June 24, 2019 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronsummers/13c659b70623b5126bc5561fd0c39e4a to your computer and use it in GitHub Desktop.
Save aaronsummers/13c659b70623b5126bc5561fd0c39e4a to your computer and use it in GitHub Desktop.
Simple plural function php
<?php
function plural( $string ) {
$last_letter = substr($string, -1); // Get the last letter of the taxonomy name
if ( $last_letter != 's' ) :
// If it ends in a "Y" replace that with "IES" otherwise add an "S"
$string = ( $last_letter == 'y' ) ? substr($string, 0, -1) . 'ies' : $string . 's';
endif;
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment