wecobble / Subtitles

Add subtitles into your WordPress posts, pages, custom post types, and themes. No coding required. Simply activate Subtitles and you're ready to go.
http://wordpress.org/plugins/subtitles/
GNU General Public License v2.0
117 stars 186 forks source link

Need additional filter to support an extension for prefixes #79

Closed actual-saurabh closed 8 years ago

actual-saurabh commented 8 years ago

Hi @philiparthurmoore,

For a project, I needed to add subtitles and prefixes to titles. Rather than reinventing the wheel, I use this plugin and it's great.

I used the the_subtitle filter in https://github.com/professionalthemes/Subtitles/blob/master/public/class-subtitles.php#L713 to add prefixes to my custom post type titles. It helps me that Subtitles has already taken the decisions that my code needs to take before displaying prefixes.

Only problem is some of my posts have a prefix, but not a subtitle. Because of https://github.com/professionalthemes/Subtitles/blob/master/public/class-subtitles.php#L586-L588, I never reach the filter.

Right now, I have two strategies:

  1. Add a placeholder subtitle when editing the post. This way, I still reach the filter. In my filter, check if it is the placeholder and then not display the title. Not very elegant, but the one that I'm using right now to avoid the second strategy.
  2. Filter the_title and single_post_title on my own and try to replicate almost everything that the the_subtitle method does somehow or duplicate and plug the class Subtitles itself. Not elegant at all.

Would you be open to adding a boolean filter that allows the code to continue at https://github.com/professionalthemes/Subtitles/blob/master/public/class-subtitles.php#L586-L588? It could be set to false when subtitles are empty, but an extension like mine could force set it to true.

If you are, I can send in a PR.

philiparthurmoore commented 8 years ago

@actual-saurabh Love the idea. Go ahead and whip up a PR for it, and I'll make sure to get it in the next release ASAP. Your use case makes total sense there. Thanks for bringing it to my attention!

philiparthurmoore commented 8 years ago

Done in https://github.com/professionalthemes/Subtitles/commit/409ef148b9d4392de50698920c2a7fcdbd755746.

philiparthurmoore commented 8 years ago

Note that documentation has been added here: https://github.com/professionalthemes/Subtitles#allow-developers-to-override-the-early-bailout-if-no-subtitle-exists.

actual-saurabh commented 8 years ago

👍