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
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.
[php]
if(function_exists(‘the_subtitle’)) the_subtitle();
[/php]
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:
[php]
if(function_exists(‘the_subtitle’)) the_subtitle( ‘<h2 class="subtitle">’, ‘</h2>’);
[/php]
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.
[php]
if(function_exists(‘the_subtitle’)) $subtitle = get_the_subtitle($post_id);
[/php]
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.
To DO:
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!
Download
Now available at WordPress: KIA Subtitle at WordPress
or check it out at the KIA Subtitle github repo
Comments
23 responses to “KIA Subtitle”
Hello, I don’t understand where to add the tag. To header.php? And on what line? Thanks.
I depends on where you want the subtitle to display. Usually, I’d guess you’d want it to follow the regular title, so you should find where that code is and place mine just below it., but ultimately it is up to you.
I’m not sure if you’ve seen this before, but I seem to be unable to delete a subtitle once I’ve created one. The Subtitle re-populates after deleting and updating the post.
… found a way around it. I just typed a space. That cleared it. Thanks!
thanks for the heads up! would you mind reporting this at github? I’ll try to sort it out asap.
Hi-
Love the simplicity of this plugin!
However it appears that including quote marks (“) in subtitles breaks the plugin. Anything after the quote neither displays nor saves.
I assume you may need to add some escape-processing filter to the code?
Thanks!
-Jeremy
Jeremy, Thanks for dropping by. I can’t seem to replicate this. I am able to save with single quotes and double quotes just fine. Are you using curly quotes as appear in your comment? My code is using
sanitize_text_field()
which should strip markup, but leave punctuation. If you are still having issues could you take it to Github?It looks like although the comments are saving, they are not displaying in the ‘subtitle’ field in the post page on the backend.
for example: http://blog.greenlightmusic.com/music-you-should-hear/videos/video-on-repeat-alt-js-fitzpleasure.html works just fine, but the ‘subtitle’ field is blank on the back-end.
it works with wp 3.5.1?
Thanx, Emanuele
Yes.
Hello and thanx for this great plugin. I wonder if the CSS can be somehow customized in the main css theme file, or if your plugin have its own css.
My plugin does not provide any CSS for styling the output of the subtitle. All styling should be handled from the theme.
When I post my post, the subtitle I typed into the box doesn’t show up on my published post on the blog.
Please re-read the “Usage” section above. You are responsible for outputting the subtitle where you’d like it to appear in your theme.
eh…for someone who doesnt understand all the fancy code speak the ‘usage’ section doesnt help. i have no idea what you’re talking about! how/where do i ‘output’ the subtitle?
The simplest usage is explained within the first paragraph.
“Wherever you want to echo the subtitle, you’d use the the_subtitle() template tag. ”
like so:
if(function_exists('the_subtitle')) the_subtitle();
There’s nothing fancy there. Where you paste this is up to where you want to display the subtitle in your theme. I’d guess somewhere near wherever the_title() is being displayed.
thanks kathy. what i meant was where do i paste the tag? into what file? and how do i access that file? sorry if these questions are very elementary
Dan, I can’t tell you what file to paste it in because it depends on your theme. It is different for everyone. You’d access your theme files either through the File Editor in the dashboard, or preferably through FTP.
Quick question: Is there a way to add an “a” tag? I’d like to be able to jump to another page on my site from a link in the subtitle.
Well I didn’t hear back from you, but I pushed the changes live to the repo anyway. You should be able to do that now.
At the moment, no. I have been using
sanitize_text_field()
to sanitize the subtitle and this strips all tags. It seems like this is more strict than what WP is doing for the actual post title, so I have changed the subtitle sanitization to match. Would you care to test it out for me? You can find the update at github.Or you can just change this line in kia-subtitle.php from:
update_post_meta( $post_id, 'kia_subtitle', sanitize_text_field( $_POST['subtitle'] ) );
to:
update_post_meta( $post_id, 'kia_subtitle', sanitize_post_field( 'post_title', $_POST['subtitle'], $post_id, 'db' ) );
Since that is the only change I have made at the moment.
Hey Kathy – the plugin works with posts but not pages, at least in my case. The subtitle field shows when creating or editing a page but when you save the text entered into the subtitle field vanishes.
KIA Subtitle Version: 1.5.4
Wordpress Version: 3.8
Thanks – Happy Holidays!
Thanks for the feedback. Bugs are better managed at Github. I can’t reproduce this on the edit post screen…seems to be saving just fine. However, there is some kind of issue with the quick edit now. Unfortunatley, my whole local setup is pretty messed up at the moment, so I don’t know when I can fix it.