Adds the ability to easily add and display a sub title/heading on any public post type.
This plugin uses a custom field to allow sub titles/headings to be added to any post type, including pages, posts and any public custom post type.
The custom subheading field is re-positioned so it is directly below the main title when editing.
Updates to your theme templates may be required in order for you to output the subheading values, please refer to the Installation instructions.
By default subheadings are also appended to RSS feeds and the admin edit post/page lists, these options and more can be modified via the settings page.
Following a plugin review by Alison Barrett (WordPress.com VIP) a number of improvements were introduced in version 1.7.
Languages: Also available in Brazilian Portuguese (Português do Brasil by mauriciomesquita).
Here we go:
subheading
folder to the /wp-content/plugins/
directory.<?php if (function_exists('the_subheading')) { the_subheading('<p>', '</p>'); } ?>
in your template files where you want it to appear, or enable the Automatically display subheadings before post content
option on the settings page.The settings for this plugin are found by navigating to the Settings
menu and selecting Reading
, with the options displayed towards the bottom of the page.
If you are not within the_loop
, you can use get_the_subheading($postID);
to fetch the value for a particular page or post.
Here we go:
subheading
folder to the /wp-content/plugins/
directory.<?php if (function_exists('the_subheading')) { the_subheading('<p>', '</p>'); } ?>
in your template files where you want it to appear, or enable the Automatically display subheadings before post content
option on the settings page.The settings for this plugin are found by navigating to the Settings
menu and selecting Reading
, with the options displayed towards the bottom of the page.
If you are not within the_loop
, you can use get_the_subheading($postID);
to fetch the value for a particular page or post.
By default subheadings are only enabled for pages, you can enable them for posts or any public custom post type via the Settings > Reading
page.
Just check the box that says Enable on Posts.
or the required post type.
The field name used is _subheading
, the underscore prefix prevents it from being displayed in the list of custom fields.
Check the RSS option on the settings page Plugins > SubHeading > Append to RSS feeds
.
Check the apply shortcode filters option on the settings page Plugins > SubHeading > Apply shortcode filters
.
This will apply any existing shortcode filters to the subheading value you have set.
Some plugins will hide the element containing the post title, which is this element that the subheading input is appended to.
You can prevent the repositioning of the input via the options page.
If you are using the option to automatically wrap the subheading content, you can include custom content before and after the subheading is displayed.
For example, setting Before to <h3>
and after to </h3>
will wrap the subheading in a h3 tag.
Using the “Automatically display subheadings before post content.” setting will prepend any subheading value before outputting any post content.
The output can be customised slightly using the “Before” and “After” fields, however if you prefer more customisation and control it is probably best to disable this setting and edit the output within your theme templates.
To display subheadings, place <?php if (function_exists('the_subheading')) { the_subheading('<p>', '</p>'); } ?>
in your template files where you want the subheading to appear.
By default the plugin uses the default list of allowed tags, which can result in certain tags such as <br />
and <p>
being removed from subheadings or settings.
This can be resolved by adding valid tags to the allowed list using either the subheading_tags
or subheading_settings_tags
filters.
If, for example, you wanted to enable the <br />
tag in subheadings, include the following function to your theme functions.php file.
add_filter( 'subheading_tags', function( $tags ) { $tags['br'] = array(); return $tags; } );
Note here that the array key 'br'
is the tag name and the values array should be a list of valid attributes for that tag, for example $tags['span'] = array('class' => array(), 'id' => array());
.
The list of default allowed tags for both subheadings and settings (before and after) is as follows:
$allowedtags = array( 'a' => array( 'href' => array(), 'title' => array()), 'abbr' => array( 'title' => array()), 'acronym' => array( 'title' => array()), 'b' => array(), 'blockquote' => array( 'cite' => array ()), 'cite' => array(), 'code' => array(), 'del' => array( 'datetime' => array()), 'em' => array(), 'i' => array(), 'q' => array( 'cite' => array()), 'strike' => array(), 'strong' => array(), );
The settings validation additioanlly allows the following tags.
... 'h1' => array( 'class' => array(), 'id' => array()), 'h2' => array( 'class' => array(), 'id' => array()), 'h3' => array( 'class' => array(), 'id' => array()), 'h4' => array( 'class' => array(), 'id' => array()), 'h5' => array( 'class' => array(), 'id' => array()), 'h6' => array( 'class' => array(), 'id' => array()), 'p' => array( 'class' => array(), 'id' => array()), ...
If you require the use of an additional tags or attributes, they will need to be added using the filters.
As of version 1.7.1 you can make use of the ‘subheading’ filter to manipulate the final output.
For example, limiting the subheading to 5 words can be done by adding the following to your theme functions.php file.
add_filter( 'subheading', function( $value ) { return wp_trim_words( $value, 5 ); } );
This example makes use of the wp_trim_words function introduced in WordPress 3.3.
If you are using older versions of PHP (< 5.3.0), you will not be able to make use of anonymous functions used in some of these examples.
Further information on the use of anonymous functions and WordPress can be read in the [WordPress Codex](https://codex.wordpress.org/Function_Reference/add_filter#Beware WordPress Codex Reference).
subheading
filter to allow output to be manipulated.is_main_query()
check to the_content
filter to ensure subheadings are only appended when cycling through the primary loop.<br />
and <p>
disappear from my subheadings?” FAQ for more information.Settings > Reading
section.get_the_subheading
function to return correctly.