5

OCD Freak: Automatically Capitalize Your Post Titles

When i was in 5th grade a had teacher who was stricter than strychnine and she enforced capital letters to be in the beginning of sentences and on the letter I when used in referring to ones self. Well obliviously Mrs. Frasca got to me and ruined my life. If your an O.C.D Freak who is lazy (Like me) then it drives you crazy when writing a post and publishing it only to realize you forgot to ca...
OCD Freak: Automatically Capitalize Your Post Titles

Checking for the functions

First thing you need to do is check if your theme has a functions.php file.

Here's how you check:

  • Login to your WordPress admin panel
  • Click Appearance
  • Then Editor

You will see the list of template files on the right side. If you see the file functions.php then you're good to go.

Coding Time

If there is not a functions.php file in your theme then create one and add:

<?php

 ?>

In between the php tags add:

/* just in case I forget to capitilize */
add_filter('the_content', ucfirst);
/* just in case I forget to capitilize the title */
add_filter('the_title', ucfirst);
/* just in case commenters forget to capitilize */
add_filter('comment_text', ucfirst);

Then upload the functions.php file to you theme directory via FTP.

The functions.php file is the first file called by WordPress in your theme.

Now to explain some of the magic!

The easy way.... excerpt from WordPress codex:

Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen.

ucfirst is a Php function that makes a string's first character uppercase.

Are you an OCD freak? If so retweet this or post on Facebook.

Shortlink:

Get automatic updates! Subscribe to Our RSS Feed or Get Email Updates sent straight to your inbox!

About the Author

server-side/front-end scubanaut I love wordpress, and spend my days wping @afj176

Level: Rookie

User Comments

( ADD YOURS )

  1. I was wondering how you would do this to be sure that a specific word in a post or comment would automatically capitalize like say for example, making sure that "Wordpress" would always have a capital W, or maybe New2WP would always have a capital N W and P.

    Or even better yet, how would you go about making sure a word would be spelled a certain way every time in case you make a typo in a word, but all the letters are there. For example, Wodrpress.

    Are these things possible?


  2. I guess I'm more OCD than you.

    "If your an O.C.D Freak who is lazy (Like me) then it drives you crazy when writing a post and publishing it only to realize you forgot to ca" -- you're.


  3. ah ha lol lol, i guess i need an auto grammer function as well thanks lol


  4. Antonio you make me laugh man! You are a dyed in the wool coder! Only a hard core OCD coder would come up with such a wonderful script. Thanks for lightening my day!

  1. Avatar

    Your Name
    May 17


    CommentLuv badge