Since the beginning of time (well, for a long time), I’ve always wanted to do something like this with my WordPress post titles:

You see, the italicised of. Or you may want to change the typeface, the colour, or style in some other way. I posted about this on Twitter and, as usual, about four million kind souls replied with their solutions.
So, how is it done? I chose to go with the brilliantly powerful custom fields. I also use these to display different header images for ILT, and alternative background images and colours on this site.
Step one: on your edit post page, just create a new custom field like so:

Then open your single.php in your themes [wp-content/themes/your_theme] folder, and find where it outputs the title of the post, and replace with something like:
<h2><a href="<?php the_permalink() ?>" title="<?php the_title_attribute() ?>">
<?php
$altitle = (get_post_meta($post->ID, "custom_title", true));
if($altitle !="") echo $altitle;
else the_title_attribute() ?>
</a></h2>
Perhaps this could be improved. Anyone? This solution works for me because it enables me to style post titles per post.
If you’d like a plugin solution, then check out Kari’s Title Style from the WordPress plugin directory. I’m using it on this site.
________________
Special thanks to @essenmitsosse and the myriad others who replied to my original tweet.
Afterthought: I wonder how you could get my above hack to work in Thematic?
12 Comments
My boss Phyllis Zimbler Miller (@ZimblerMiller) figured out that you can put a <em> in title field — no extra code necessary. Try just using <em></em> in the title field — see what happens.
Hadn’t thought of that. I wonder how SEO-friendly that is?
Annoying that it isn’t possible to directly write the html. A necessary evil I guess, but again good work from Kari
Esben:
I’m sure Kari could get that plugin to fry eggs and make coffee. Just give him a few minutes :)
The problem why this naturally don’t work is, that html doesn’t work for the title in the head. You would need one title with and one without html. Or at least I guess thats the original reason …
I have no clue if there’s just something different with my install, but I’ve never had problems with HTML in the title. It’ll show the escaped title in the wp-admin, but the actual post will show the styled content. I can’t find anything in the settings.
When you tried, would it just show “STYLING <em>of</em> WORDPRESS?”
Maybe it has something to do with my database? Maybe I forgot to escape things?
@Yael K. Miller
Hadn’t taken that into account, and already had to push one bug fix.
@Esben Thomsen
How would you like to be able to input the HTML?
I know I have seen a plugin somewhere that makes the post titles editable with a WYSIWYG…
I googled it and looked on the Extend db, to no avail. This was the closest I found
It might be smarter (more future-compatible, and more semantic) to put the word “of” in span tags instead; something like:
<span class="special">of</span>I also have used em tags in the title field without problem, though usually for actual emphasis or titles of works.
I tried to argue for this ages back and was rebutted:
http://core.trac.wordpress.org/ticket/1371
I still think Otto42 was fundamentally wrong, in that he concluded that any and all HTML in titles would be purely presentation, while what I was trying to assert, and continue to, is that the likes of em and code are actually semantic in nature and should be allowed in titles. But I didn’t have time to debate with a developer who wasn’t open to reason and obviously wasn’t going to change his mind, so I gave up.
The fact that plugins have sprung up shows there’s still a desire for it, but I don’t think it’ll ever gain official integration into the WordPress core. Ah well!
The reasoning behind the plugin was that I didn’t want to touch the original titles, just alter them on the fly. Otherwise you might run into problems.
I just tried it today and noticed, that it’s really working to put in the normal title. I don’t know why I thought, it wouldn’t work.
One Trackback
[…] this page was mentioned by David McKendrick (@davidandgoliath), Grameen Solutions (@grameensol), Asif Anwar (@asifanwar4seo), Andrew (@bacbay), Michael Davis (@web2feed) and others. […]