Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Users can enter term entries in a a taxonomy box (hierarchical) and I want to force that the entries be capitalized (first letter each word).

I tried adding text-transform:uppercase css to the entry box and although it capitalizes the words "during-typing", it still doesn't register it as capitalized when the term is added to the entry.

Meaning if the user doesn't press Shift to capitalize the words, it will show capitalized on the entry box (because of the css), but it will not show capitalized inside the taxonomy box.

Reasons why this is needed:

1) In the front-end when displaying artists names, example like Michael jAckson, or bruce Springsteen, it wouldn't look good in the front end.

2) Another reason is in the taxonomy box, it doesn't look good when the artists' names are not capitalized.

So any answers to the main issue?

Edit: I think an alternative I thought of is to put like a form validation, so when the user clicks "Add New" a popup box will appear saying that he must capitalize the words correctly. The problem is, I'm not very good at javascript, so I don't know what the code is.

Can anyone provide the code to validate the entry in the taxonomy box if its capitalized correctly when the user clicks the 'Add New' button?

share|improve this question
1  
Reason for this is users enter something like "michael Jackson" or "Bruce springsteen", doesn't look good in the front end. –  John Mar 5 '12 at 6:25
    
Good example. +1 Could make this an edit of your Question? –  kaiser Mar 5 '12 at 14:32
add comment

2 Answers 2

PHP has a function that does EXACTLY what you're looking for, ucwords(). Leave the CSS capitalize on there, so that the users know it will be auto-capitalized, and then when you're filtering the input (which you should be doing ANYWAYS, since it's user input, run it through ucwords() right before database insertion.

share|improve this answer
    
I tried ucwords() and although it works in the output, in the taxonomy box, artist names can still be non-capitalized. So I think what I'm after is something that autocapitalizes the taxonomy box entries. –  John Mar 9 '12 at 14:22
add comment

You don't need to add that CSS to the admin area - you need to add text-transform: capitalize; to the HTML output. So say for example your meta value was output in <div class="entry-meta">, your css would looks like this: .entry-meta { text-transform: capitalize; }.

This way, the user can type the information in however they want, for example: "this IS somE mETa Information", and it would looks like this in the browser: "This Is Some Meta Information".

EDIT: On second read, I realize you may mean that you do indeed want the user's words to be capitalized in the back-end - but you need to use jQuery for this solution, not CSS. Since my answer above would solve the problem when the meta value is output, further work on capitalizing the user's input would be a waste of time and resources to be perfectly honest.

share|improve this answer
    
You're only touching the output, not the data saved in the DB. –  kaiser Mar 5 '12 at 0:33
    
If that is the desired effect then jQuery and/or some regular expressions would be required. Unfortunately I don't have the time to come up with a complete answer. There's a pretty good chance that a plugin already exists for that thought! –  cmegown Mar 5 '12 at 1:46
    
A plugin for capitalizing taxonomy terms? :) –  kaiser Mar 5 '12 at 4:33
    
@kaiser instead of being sarcastic and correcting me, you might try answering the question. I'm giving my two cents, and if I am incorrect, please answer so that we can all learn from it - much like m0r7if3r does below. –  cmegown Mar 5 '12 at 14:27
    
That wasn't meant sarcastic. I just wanted to push you a little to correct the answer and maybe come to some solution that still has upvotes in a year. You're new here, I'm not, so I just tried to help. (Therefore the smilie - I personally hate them). @m0r7if3r does the exact right thing. The missing point still is on which filter/hook this should be run. –  kaiser Mar 5 '12 at 14:31
show 2 more comments

Your Answer

 
discard

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.