Customizing WordPress Page Titles

I don’t know about you, but the short title necessary to fit the page name in the list of pages across the top navigation bar, really chaps my butt.

You have to keep the page *name* small (like one or two words max), but that means the *title* is displayed with that one or two words. And before you write in to tell me there are plugins to override the browser title area for a page, let me mention, that’s not what chaps me. I mean the main title displayed on the page.

Let me give you an example you have probably seen: There is an ABOUT page, and even though you can stuff *About Cenay Nailor* in the browser title, only About is displayed on the actual page.

Like most programmers plagued by some stupid behavior, I came up with a way around it. Let me share that with you.

Add a custom field to the page (in my example, I named it customtitle) and place your more descriptive text here. Then pop over to the theme editor and update the page.php (for most WordPress installations and themes) like so:

(Original line)

<h1>< ?php the_title(); ?></h1>

(Replace with)

<h1><?php $key="customtitle"; echo get_post_meta($post->ID, $key, true); ?></h1>

I also added the original line just below my new line, but changed the h1 to an h3 tag. This gives me custom text in the larger font, and the actual page title in the smaller header tag.

Since the advent of WordPress 3.0, custom menus are available which will let you create a page name as large as you want it, but display custom text in the menu. While this partially solves our problem (menu-wise), when the page name is listed in the *pages* sidebar widget, you get the complete name. You can optionally add the “custom menu” to the sidebar.

Leave a Reply

Your email address will not be published. Required fields are marked *