[WordPress] 外掛分享: WP Subtitle

WordPress 外掛 WP Subtitle 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「WP Subtitle」是 2009-07-08 上架。
  • 目前有 10000 個安裝啟用數。
  • 上一次更新是 2024-04-23,距離現在已有 375 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 5.6 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 5.6 以上。
  • 有 21 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

husani | husobj |

外掛標籤

title | content | subhead | subtitle | subheading |

內容簡介

WP Subtitle 外掛能讓你的頁面和文章擁有副標題。這個短小的文字通常出現在文章(或頁面)標題之下,也可以在你選擇的任何地方插入你的樣板。

你可以使用以下 API 在你的主題樣板檔案(或外掛)中插入副標題:

顯示副標題

所有參數都是選用的。如果省略「post_id」參數,則使用迴圈中目前文章的 ID。

PHP 程式碼:

do_action( 'plugins/wp_subtitle/the_subtitle', array(
'before' => '

',
'after' => '

',
'post_id' => get_the_ID(),
'default_value' => ''
) );

輸出結果:

My Post Subtitle

取得副標題

所有參數都是選用的。如果省略「post_id」參數,則使用迴圈中目前文章的 ID。

當文章沒有副標題時,可以將預設值作為第二個參數提供給 apply_filters。如果要回傳一個空字串,請將預設值留空。

PHP 程式碼:

$subtitle = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
'before' => '

',
'after' => '

',
'post_id' => get_the_ID()
) );

結果:

$subtitle = '

My Post Subtitle

'

參數

plugins/wp_subtitle/the_subtitle 動作和 plugins/wp_subtitle/get_subtitle 過濾器所接受的引數陣列包括:

before
(string) 如果有副標題,將文字插入標題之前。預設值為空字串。

after
(string) 如果有副標題,將文字插入標題之後。預設值為空字串。

post_id
(integer) 文章、頁面或自訂文章類型 ID。

default_value
(string) 只有 plugins/wp_subtitle/the_subtitle 動作會使用此參數,讓你指定資料庫中沒有副標題的文章顯示的預設副標題。對於 plugins/wp_subtitle/get_subtitle 過濾器,請改用 apply_filters 的第二個參數。預設值為空字串。

文章類型支援

預設上,副標題支援文章和頁面。如果要在自訂文章類型中加入支援,可以將以下程式碼加入主題的功能檔案或外掛中:

add_post_type_support( 'my_post_type', 'wps_subtitle' )

WooCommerce 外掛支援

無需更改樣板,即可自動將副標題添加到 WooCommerce 的產品中。在管理區中,點選「WooCommerce」>「設定」>「產品」,你可以選擇:

啟用產品副標題
在單一商品頁面上顯示副標題
在產品檔案庫(分類頁面)上顯示副標題

Yoast SEO 和 SEOPress 外掛支援

此外掛讓你可以透過 Yoast SEO 和 SEOPress 外掛將副標題加入您的 Meta 標題和描述中。

與 Yoast 的 %%title%% 佔位符類似,可以使用 %%wps_subtitle%%。

對於自訂分隔符,也有額外的佔位符和過濾器可供您自訂。

更多資訊,請參閱

原文外掛簡介

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' => '

',
'after' => '

',
'post_id' => get_the_ID(),
'default_value' => ''
) );

Output:

My Post Subtitle

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' => '

',
'after' => '

',
'post_id' => get_the_ID()
) );

Result:
$subtitle = '

My Post Subtitle

'

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.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WP Subtitle」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 2.6 | 2.7 | 2.8 | 2.9 | 3.0 | 3.1 | 3.2 | 3.3 | 3.4 | 2.0.1 | 2.3.1 | 2.3.2 | 2.4.1 | 2.7.1 | 2.8.1 | 2.9.1 | 3.3.1 | 3.4.1 | trunk |

延伸相關外掛(你可能也想知道)

暫無相關外掛推薦。

文章
Filter
Apply Filters
Mastodon