benhuson / wp-subtitle

Development of the WordPress WP Subtitle plugin. http://wordpress.org/plugins/wp-subtitle/
34 stars 16 forks source link

Please add default_subtitle() #20

Closed dotherightthing closed 8 years ago

dotherightthing commented 8 years ago

I'd like to use your plugin to output custom field values above the featured image.

This means that I only ever populate the subtitle programatically via:

add_filter( 'the_subtitle', 'my_function' );

However this only works if the subtitle has a value assigned, otherwise nothing is output.

There is a default_title function in Wordpress (https://developer.wordpress.org/reference/hooks/default_title/). If you could add a default_subtitle function I would be able to programatically set a default value for the purpose of overwriting this with the code above.

Many thanks, Dan

benhuson commented 8 years ago

Hi Dan,

Please try downloading the feature/default_subtitle development branch of the plugin and see if this works for you: https://github.com/benhuson/wp-subtitle/tree/feature/default_subtitle

It introduces a default_subtitle filter (like the WordPress default_title filter) which you can use like this:

function my_default_subtitle( $post_title, $post ) {
    // $post is the current post object if you want to customise the default subtitle 
    return 'My Default Subtitle';
}
add_filter( 'default_subtitle', 'my_default_subtitle', 10, 2 );

Will that work for you?

Let me know and if it looks good I'll merge into the core plugin.

Thanks

Ben

benhuson commented 8 years ago

Please note, the filter has now been changed to wps_default_subtitle and is available in version 2.8