Giter Site home page Giter Site logo

wp-subtitle's Introduction

WP Subtitle

Add subtitles (subheadings) to your pages, posts or custom post types.

The WP Subtitle plugin allows your pages and posts to contain a subtitle. Also called a sub-heading, this this short line of text is meant to appear beneath a post's (or page's) title, but can be inserted in your template wherever you choose.

The subtitle can be inserted into your theme template files (or plugin) using the following API:

Display The Subtitle

All parameters are optional. If 'post_id' is omitted then the current post ID in the loop is used.

PHP Code:

do_action( 'plugins/wp_subtitle/the_subtitle', array(
    'before'        => '<p class="subtitle">',
    'after'         => '</p>',
    'post_id'       => get_the_ID(),
    'default_value' => ''
) );

Output:

<p class="subtitle">My Post Subtitle</p>

Get The Subtitle

All parameters are optional. If 'post_id' is omitted then the current post ID in the loop is used.

A default value can be supplied as the second parameter for apply_filters. This will be used if the post does not have a subtitle. Leave as an empty string to return an empty string if the post does not have a subtitle.

PHP Code:

$subtitle = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
    'before'  => '<p class="subtitle">',
    'after'   => '</p>',
    'post_id' => get_the_ID()
) );

Result:

$subtitle = '<p class="subtitle">My Post Subtitle</p>'

Parameters

The array of arguments accepted for the plugins/wp_subtitle/the_subtitle action and plugins/wp_subtitle/get_subtitle filter are:

before
(string) Text to place before the subtitle if one exists. Defaults to an empty string.

after
(string) Text to place after the subtitle if one exists. Defaults to to an empty string.

post_id
(integer) Post, page or custom post type ID.

default_value
(string) Only used by the plugins/wp_subtitle/the_subtitle action, allows you to specify a default subtitle to display if the post does not have one. For the plugins/wp_subtitle/get_subtitle filter the second parameter of apply_filters should be used instead. Defaults to to an empty string.

Post Type Support

By default, subtitle are supported by both posts and pages. To add support for custom post types add teh following to your theme functions file or plugin:

add_post_type_support( 'my_post_type', 'wps_subtitle' )

WooCommerce Plugin Support

Subtitles can automatically be added to your WooCommerce products without needing to make template changes. In the admin go to WooCommerce > Settings > Products where you can choose to:

  • Enable Product Subtitles
  • Display the subtitle on single product pages
  • Display the subtitle on product archives (category pages)

Yoast SEO and SEOPress Plugin Support

The plugin allows you to include the subtitle in your meta titles and descriptions via the Yoast SEO and SEOPress plugins.

Similar to the Yoast %%title%% placeholder which inserts the post title, you can use %%wps_subtitle%%.

There are also addition placeholders and filters to allow to to customize seperators for the subtitle.

For more information, view the SEO support documentation here.

Installation

  1. Upload the WP Subtitle plugin to your WordPress site in the /wp-content/plugins folder or install via the WordPress admin.
  2. Activate it from the Wordpress plugin admin screen.
  3. Use the API to display the subtitle in your theme.

For full details on the API and how to display the subtitle, view the documentation here.

Frequently Asked Questions

What does WP Subtitle do?

The plugin adds a Subtitle field when editing posts, pages or custom post types. The subtitle is stored as a custom field (post meta data) and can be output using API actions and filters.

Where does WP Subtitle store the subtitles?

All subtitles are stored as post meta data. Deactivating this plugin will not remove those fields.

Compatibility with WordPress 5.0+

In the new editor in WordPress 5.0 the subtitle is editable via a panel in the sidebar (like excerpts).

How do I add the subtitle to my pages?

Refer to the documentation.

How do I add support for custom post types?

To add support for custom post types add the following to your theme functions file or plugin:

function my_wp_subtitle_page_part_support() {
	add_post_type_support( 'my_post_type', 'wps_subtitle' );
}
add_action( 'init', 'my_wp_subtitle_page_part_support' );

Where can I get help?

Please post support requests and questions in the WordPress.org Support forum.

How should I report a bug?

Please submit bugs/errors directly to the GitHub Issues list.

How can I contribute code?

The plugin is hosted on GitHub and pull requests are welcome.

Upgrade Notice

3.4.1

Resolve XSS issue by improving sanitization when saving subtitle custom field.

3.4

Added support for the SEOPress plugin and updating the subtitle via the REST API.

3.3.1

Fixed broken closing H2 tag for WooCommerce subtitle.

3.3

New API for getting and displaying the subtitle using do_action( 'plugins/wp_subtitle/the_subtitle' ) and apply_filters( 'plugins/wp_subtitle/get_subtitle', '' ). Please see the documentation.

3.2

Fix WordPress 5.0 compatibility.

3.1

WooCommerce compatibility: Go to WooCommerce > Settings > Products > Display for settings. Yoast SEO compatibility: Added %%wps_subtitle%% placeholders. Gutenberg compatibility: Use metabox UI.

3.0

Make wps_subtitle available via WordPress REST API.

2.9.1

Fix preview not rendering correct template and other post meta.

2.9

Add support for revisions and fix special character encoding.

2.8.1

Fix PHP warning - get_admin_subtitle_value() should be declared static.

2.8

Allow subtitle to contain HTML (same as main post title ) and add wps_default_subtitle filter.

2.7.1

Fix incorrect post ID reference preventing subtitle from saving.

2.7

Trim subtitle and wptexturize() by default.

2.6

Added quick edit support for subtitle. Security Update: Sanitize $_REQUEST and $_GET when establishing post type in the admin.

2.5

Add [wp_subtitle] shortcode. Do not use variable for textdomain - causes issues for parsers.

2.4.1

Fix PHP notice warning on 404 error page.

2.4

Add subtitle admin column.

2.3.1

Security Update: Ensure subtitles are sanitized when saving.

2.3

Prevent subtitle fields from displaying on unsupported post types and fix issue with quotes in subtitles.

2.2

Subtitle field moved to below title field (only in WordPress 3.5+)

2.1

Fixed static method warnings and only load admin functionality when needed.

2.0

Added custom post type support and support for more recent versions of WordPress.

1.0

Initial release.

Changelog

View a list of all plugin changes in CHANGELOG.md.

wp-subtitle's People

Contributors

benhuson avatar chriselkins avatar fabianmarz avatar hatsumatsu avatar jaywilliams avatar ocean90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wp-subtitle's Issues

Localization and WP Subtitle

Hi,

I currently use the WPGlobus plugin to localise my posts.
Unfortunately WPGlobus doesn't recognise the subtitle added through WP Subtitle.

Is there any way to add translations for the subtitle? Or has somebody got wp-subtitle working with WPGlobus?

Thank you!

Problems with special characters in latest update?

Hello, these past few days we have been having some troubles with special characters in our WordPress posts' subtitles, particularly with some of the Spanish á é í ó ú, which sometimes (but not always) appear as ó and similar.

Since there has been a plugin update recently, I was wondering if it could be related, or there was any known bug.

A couple examples:
http://www.somosbasket.com/2016/09/17/noticias/masai-ujiri-toronto-es-mi-hogar/
http://www.somosbasket.com/2016/09/17/noticias/joel-embiid-no-back-to-back/

Thanks! (:

Add Support To Rank Math SEO plugin

First of all thanks a lot for this awesome and amazing plugin. But I think in the SEO world Rank Math is also a great plugin. I have used it in some of my client sites and I am super satisfied with it. I started to prefer it over Yoast. So, I think it would be great id you also add the Rank Math support.

Duplicate Subtitle Found

I used this plugin and then deactivated it. Used another plugin. But I can see that your plugin shows the sub-title at a new location - a duplicate version of the sub-title. Ok, here's a screenshot for your reference.
khurda cuttack among diabetes hotspots in country

I have tried deleting the custom field it created so I could make it disappear from below the header, but it hasn't worked at all.

Pass the current post object to the wps_subtitle_field_placeholder filter

The wps_subtitle_field_placeholder doesn't provide access the current post object. This is different from the wps_subtitle_field_description filter.

// Description
$description = apply_filters( 'wps_subtitle_field_description', '', $post );

echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( $value ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';

WP API support

I would like the subtitle to be returned in a /wp-json/wp/v2/posts request.

wps_subtitle_key filter does not affect all cases of the subtitle meta key

The plugin defines a filter wps_subtitle_key which changes the post meta key used to store the subtitle:

/**
* Get Default Subtitle
*
* @since 2.8
*
* @return string Default title.
*/
public function get_default_subtitle() {
return apply_filters( 'wps_default_subtitle', '', $this->post_id );
}

However, this filter doesn't affect the meta key used in the REST endpoint:

update_post_meta( $object->ID, 'wps_subtitle', wp_kses_post( $value ) );

There are several other places in the plugin that similarly use a hardcoded wps_subtitle meta key instead of the filter output. https://github.com/benhuson/wp-subtitle/search?l=PHP&q=wps_subtitle

avoid post_meta bloat by not saving blank meta entries

I noticed that my post_meta table has hundreds of thousands of blank post_meta table entries for the wps_subtitle meta key (it is, mind you, a large site), which since a call to get_post_meta() returns an empty string if the field is not set, it is the same as having an empty record set, therefore these blank entries prove to be an unnecessary bloat to the post_meta table.

This bloat can be easily solved by changing the calls to update_post_meta to only update if the subtitle is not blank, otherwise use delete_post_meta instead.

Subtitle not working on admin preview page

Each time I preview a post with subtitle, I get the output below where the subtitle is supposed to display.

Notice: Trying to get property of non-object in /path/to/webroot/wp-content/plugins/wp-subtitle/includes/subtitle.php on line 86.

Screenshot 2019-03-29 at 10 09 04 PM

wp-subtitle

I am using wp-subtitle the plugin in wordpress. Until yesterday the subtitles were displaying just fine on the website, however they have stopped displaying all of a sudden today. I have checked setting nothing has changed. I tired removing the plugin and adding it back again but nothing works. my website is http://www.factledge.com/?p=460

Opening PHP-Tag

Could you please change the opening php tag from the asp/legacy version (<?) to the regular one (<?php) ? the plugin will crash the wordpress installation on modern webhosting environments with disable asp like tags.

thanks for the great plugin!
best regards, Andi

Include Subtitle in RSS Feed

Currently the subtitle does not get pulled into the RSS feed. I would like it to be displayed afterward. It looks like currently the only way to accomplish this is to override the feed generation functions but it would be great to see this feature included in future versions.

Please add default_subtitle()

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

hi

@benhuson Hi. I would like to have your help for one thing that there regarding with my control-player.php. thank

Preview of custom post type doesn't show subtitle

When previewing a custom post type post (via the preview link on the edit post screen) the subtitle doesn't appear.

Looking at the code of includes/subtitle.php (Link) you're checking for a preview_id GET parameter.
It seems that this parameter is not present in custom post types where the URL looks like https://example.com?post_type={custom_post_type}&p={post_id}&preview=true .

I can prepare a PR if required.

Change the title "Subtitle" in post list table

Hi, I would like to have the same title that I have set with my_wps_meta_box_title function also in post list heading table. Below exactly where I mean.

image

In particoular, I've needed for a custom post type.

Thank you very much

WP-Subtitles: field disappeared

hi, I've removed "subtitle field" and now it doesn't appear anymore.

I take this screenshot from another website
2017-05-18-subtitle field
exactly I have push on check "remove/Rimuovi" because I supposed that the message box should not appear any more, instead the Subtitle field disappeared
thanks in advance
bye bye

Subtitle Content Disappearing

After inputting content into the subtitle field, it disappears after updating the page to reflect that content. Really hope I can use this plugin, because it's been really great so far!

Getting subtitle for Posts page.

I'm unable to display the subtitle for the page that is specified to show the latest posts. I cannot use the_subtitle() as I'm not in within The Loop, nor am I able to find the page ID to use the other method get_the_subtitle(). I'm looking for something like the single_post_title that is being used to display the title. (e.g. twentyseventeen/index.php:23)

Apply smart quotes on subtitle

It would be great if the the_subtitle() would automatically apply wptexturize() on its output to take advantage of smart quotes and all the other typographic miracles WP offers.

I can make a PR if you like...

How to call wp subtitle function as og:title to Facebook Open Graph Meta Data in function.php

I am using wp subtitle plugin for headings in my Local language, and default wordpress title as English headings. I need the plugin generated subtitle as title of shared article on facebook.

I use code shown below (in function.php) as Facebook Open Graph Meta Data to achieve My goal.
but only I get default wordpress title as og:title content. Here is the code in function php.

//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
    return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'add_opengraph_doctype');

//Lets add Open Graph Meta Info

function insert_fb_in_head() {
    global $post;
    if ( !is_singular()) //if it is not a post or a page
        return;
    echo '<meta property="fb:admins" content="XXXXXXX"/>';
    echo '<meta property="og:title" content="' . get_the_subtitle() . '"/>';
    echo '<meta property="og:type" content="article"/>';
    echo '<meta property="og:url" content="' . get_permalink() . '"/>';
    echo '<meta property="og:site_name" content="KERALA NEWS"/>';
    if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
        $default_image="http://www.example.com/wp-content/themes/dw-focus-master/assets/img/logo.png"; //replace this with a default image on your server or an image in your media library
        echo '<meta property="og:image" content="' . $default_image . '"/>';
    }
    else{
        $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
        echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
    }
    echo "
    ";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.