KIA Subtitle

now out subtitle input is always in the right place

now our subtitle input is always in the right place

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:

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

Posted in

23 Comments

  1. mon on September 15, 2012 at 4:41 am

    Hello, I don’t understand where to add the tag. To header.php? And on what line? Thanks.



    • kathy on September 15, 2012 at 12:06 pm

      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.



  2. dwcouch on September 28, 2012 at 2:35 am

    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.



    • dwcouch on September 28, 2012 at 2:37 am

      … found a way around it. I just typed a space. That cleared it. Thanks!



    • kathy on September 28, 2012 at 2:47 am

      thanks for the heads up! would you mind reporting this at github? I’ll try to sort it out asap.



  3. Jeremy Meyers on February 6, 2013 at 4:48 pm

    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



    • kathy on February 6, 2013 at 7:34 pm

      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?



  4. emanuele on February 12, 2013 at 5:49 pm

    it works with wp 3.5.1?

    Thanx, Emanuele



    • kathy on February 13, 2013 at 4:29 am

      Yes.



  5. Adrian on February 14, 2013 at 5:37 am

    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.



    • kathy on February 14, 2013 at 1:12 pm

      My plugin does not provide any CSS for styling the output of the subtitle. All styling should be handled from the theme.



  6. Alison on March 21, 2013 at 1:25 am

    When I post my post, the subtitle I typed into the box doesn’t show up on my published post on the blog.



    • kathy on March 21, 2013 at 8:01 am

      Please re-read the “Usage” section above. You are responsible for outputting the subtitle where you’d like it to appear in your theme.



      • dan on March 23, 2013 at 7:19 pm

        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?



        • kathy on March 24, 2013 at 10:38 am

          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.



          • dan on March 27, 2013 at 3:36 pm

            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



          • kathy on March 27, 2013 at 4:02 pm

            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.



  7. Joe on October 10, 2013 at 8:23 pm

    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.



    • kathy on October 18, 2013 at 3:29 pm

      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.



  8. kathy on October 11, 2013 at 10:46 am

    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.



  9. Tim on December 26, 2013 at 4:03 pm

    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!



    • kathy on December 31, 2013 at 4:42 am

      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.