WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to check the if the first letter of a field is capitalized.


If (First Name field) is capitalized {


} else {

Not Capitalized!



Thank you

share|improve this question
not a specific wordpress question; possibly try the other suggestions, but with php.net/manual/en/function.ucfirst.php – Michael Nov 9 '11 at 17:10
Ok will do! Thanks Michael – user1893 Nov 9 '11 at 17:12
up vote 1 down vote accepted
$field = 'First Name';

if(ucwords($field) !== $field){
 // not capitalized

 // capitalized


see ucwords()

share|improve this answer
Thanks One Trick Pony, I'll try it out! – user1893 Nov 9 '11 at 15:56
I ran your solution in a loop that goes through all the users, but the didn't want to use the else statement. And for some reason when I set $field = get_user_meta($user->ID, 'display_name', true); I get a list of all the users and this indicates that the field is not capitalized. It should only show the users with the "display_name" not capitalized. Do you know what's wrong? – user1893 Nov 9 '11 at 16:48
It seems to work now, but I used the "nickname" field instead of "display_name." I think because the display name is based on the nickname by default (dynamically) I wasn't able to tell if it was capital or not. Using a field with a preexisting value the function worked. Thanks! – user1893 Nov 9 '11 at 17:27

Use this to check the first letter of each word -

if(ucwords($name) === $name) :
    { First letter is capitalised }
else :
    $name = ucwords($name);

Or you can use ucfirst() for only the first letter of the field.

If you know for sure that you wan't it in upercase though, you don't have to worry about the check, just run do $name = ucwords($name); and PHP wont do anything if it does not need to.

share|improve this answer
Thanks for the help David! – user1893 Nov 9 '11 at 16:01
After running the your if statement, I get results that show that all of the users' field is not capitalized and I don't understand why is that... – user1893 Nov 9 '11 at 16:56
Figured out the problem. I needed to use a field an existing value in it. I used the nickname instead of display_name (as I was using in my code). Thanks a lot. – user1893 Nov 9 '11 at 17:29
You are welcome. – David Gard Nov 10 '11 at 17:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.