1

I have about 2000 post with the titles in the following format:

[i like apples]

I want make them:

[I Like Apples]

I used the WP Title Case plugin, but the problem is that this plugin is only capitalizing the title of the post itself, so just h1 looks normal but <title> in <head> is still not capitalized. I guess the real non-capitalized titles are being fetched from database.

Maybe there is a SQL script to capitalize the column in the table of the database or a php script to change the <title> in head into normal format?

2

EDIT: WP Title Hook

Ok, so if you're using wp_title (which you probably are, it's default) that function should have two filters in it you could use.

The first one is wp_title_parts, which returns your title broken up into an array.

function wp_title_capitalize( $title_parts ) {

    // Only uppercases the words of the first element (should be the page title)
    $title_parts[0] = ucwords( $title_parts[0] );

    return $title_parts;

}
add_filter( 'wp_title_parts', 'wp_title_capitalize' );

OR if you're ok with running the uppercase filter on the whole thing, you can run it on wp_title

function wp_full_title_capitalize( $title, $sep, $seplocation ) {

    // Uppercases the entire title
    $title = ucwords( $title );

    return $title;

}
add_filter( 'wp_title', 'wp_full_title_capitalize' );

The second answer is easier to understand, since it runs on the whole thing, but if your titles look like

About Us | COMPANY NAME

Then, you probably want to go with the first option.

As always, with hooks & filters, these go in functions.php of your theme.

Old Answer (CSS ONLY)

If you're only worried about the display, you can just apply

text-transform: capitalize;

to the CSS of your h1.

http://www.w3schools.com/cssref/playit.asp?filename=playcss_text-transform&preval=capitalize

  • Good answer, Thank you, but as far as I know css is not working for <title> tag in <head> – Adam S. Nov 2 '16 at 3:38
  • Yeah, CSS won't affect that. Sorry, I read your question wrong. I'll edit the question with an addendum answer. – socki03 Nov 2 '16 at 13:42
1

You can use wordpress hooks in functions.php but as socki03 answered I think this is abit better

add_filter( 'wp_title', 'ucwords' );

I still believe this is abit overkill

function wp_full_title_capitalize( $title, $sep, $seplocation ) {

    // Uppercases the entire title
    $title = ucwords( $title );

    return $title;

}
add_filter( 'wp_title', 'wp_full_title_capitalize' );

I can't comment his answer so i am leaving this as a answer :)

  • I'm going to be honest, I've never used straight up PHP functions in an add_filter scenario. Upvoting for me learning something. Love the simplicity. Only reason I'd use mine is if you want a bit more control, or explanation. – socki03 Nov 2 '16 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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