Recently I was working on a project and needed a subtitle. There are probably two subtitle plugins already in existence. I happened to pick The Subtitle by Luc Princen, which worked pretty much as intended except the actually input box wasn’t always where it was supposed to be and I found that admin notices seemed to make it pretty unreadable and not totally obvious to my clients.
Well instead of seeing if this problem was solved in the other, already-available plugin, I did what I always do when I have more important things I could be working on: I fixed it. I went ahead and tweaked a bunch of other things too: like moving the plugin into a class (I have no idea if this is beneficial, but I feel smart doing it so I do), not saving “Subtitle” as the meta on posts with no subtitle instead of relying on the callbacks to not display it. Making it translation-ready… with a whopping 1 translatable string. Oh and just because I am all multi-lingual like that (meaning I can use translate.google.com) I translated it into french and spanish.
Usage is covered in the readme.txt but I’ll cover it again here. Wherever you want to echo the subtitle, you’d use the the_subtitle() template tag. We’re wrapping it in the function_exists wrapper in case you decide to uninstall the plugin (why?), this way your theme won’t break.
As of version 1.2, the_subtitle() accepts three parameters: a string to come before the subtitle, a string to come after the subtitle, and whether or not to echo the subtitle: true by default. Basically we are mimicking the capabilities of WordPress’s default the_title() function.
So for example, you can wrap the subtitle in some HTML tags using the first two parameters:
if(function_exists(‘the_subtitle’)) the_subtitle( ‘<h2 class="subtitle">’, ‘</h2>’);
If you need to return the value, much like the default WordPress functions, you can use get_the_subtitle() which accepts a $post_id parameter if you need to use it outside the loop. If you do not supply a $post_id, it will automatically grab the ID from the current post. But if you supplied a number there, you could ostensibly use it to grab the subtitle of another post.
if(function_exists(‘the_subtitle’)) $subtitle = get_the_subtitle($post_id);
Oh, and I left the shortcode in tact, though I can’t figure out why you’d use the shortcode instead of just straight typing into the post editor. But if you want it, it is still:
[ the-subtitle ]
with no spaces.
I’m wondering if it is worthwhile to add a subtitle column to the edit screen and if I should then add it to the “quick edit”. Let me know your opinion in the comments!
Now available at WordPress: KIA Subtitle at WordPress
or check it out at the KIA Subtitle github repo