开发者 |
husobj
husani |
---|---|
更新时间 | 2024年4月24日 06:49 |
捐献地址: | 去捐款 |
PHP版本: | 5.6 及以上 |
WordPress版本: | 6.5.2 |
版权: | GPLv2 |
版权网址: | 版权信息 |
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>'
参数
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:
%%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.
/wp-content/plugins
folder or install via the WordPress admin.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.
All subtitles are stored as post meta data. Deactivating this plugin will not remove those fields.
In the new editor in WordPress 5.0 the subtitle is editable via ap panel in the sidebar (like excerpts).
Refer to the documentation.
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' );
Please post support requests and questions in the WordPress.org Support forum.
Please submit bugs/errors directly to the GitHub Issues list.
The plugin is hosted on GitHub and pull requests are welcome.
wps_subtitle_field_placeholder
filter. Props Dominik Schilling.do_action( 'plugins/wp_subtitle/the_subtitle' )
.apply_filters( 'plugins/wp_subtitle/get_subtitle', '' )
.wps_meta_box_title
filter.use_block_editor_for_post_type
.%%wps_subtitle%%
placeholders for Yoast SEO compatibility.WooCommerce > Settings > Products > Display
for settings.wps_subtitle_field_position
filter to show subtitle admin field before_title
, after_title
or in meta box.wps_subtitle
available via WordPress REST API.esc_attr()
AND htmlentities()
- can mess up special characters.get_admin_subtitle_value()
should be declared static.wps_default_subtitle
filter.WP_Subtitle
class to validate saving of subtitle in the admin.$_REQUEST
and $_GET
when establishing post type in the admin.wps_subtitle_key
.<?php
instead of just <?
.