the_title Hook in WPFTS
The the_title hook is a WordPress filter that allows modification of a post’s title before it’s displayed on a page. WPFTS utilizes this filter to apply Smart Excerpts to post titles displayed in search results.
What WPFTS Does When the_title is Called:
-
Condition Check: WPFTS verifies the following conditions:
- The plugin is active and the Smart Excerpts option is enabled (
is_smart_excerpts). - The request is on a search results page (
is_search()). - The request is not from the admin panel (
!is_admin()). - The title is displayed within the WordPress loop or in a
post-titleblock type (in_the_loop()). Additional check for compatibility with the Gutenberg block editor. - Or, if
$wpfts_core->forced_se_queryis not equal tofalse, meaning Smart Excerpts was forcefully called (e.g., in a widget).
- The plugin is active and the Smart Excerpts option is enabled (
-
Applying Smart Excerpts to the Title: If all conditions are met, WPFTS creates a
WPFTS_Result_Itemobject for the current post and calls itsTitleText()method. This method returns the title with applied Smart Excerpts styling and potentially an added file extension (for attachments).
Important Functions Involved in the_title Processing:
WPFTS_Core::get_option()is_search()is_admin()in_the_loop()WPFTS_Result_Item::TitleText()WPFTS_Core::ForceSmartExcerpts()(checks the value of$wpfts_core->forced_se_query)
How to Use This in Addon Development:
Addon developers should be aware that WPFTS modifies post titles in search results when using Smart Excerpts. If your addon also modifies titles, ensure your logic doesn’t conflict with WPFTS. You can use the wpfts_se_titletext filter for finer control over title display in search results.
Additional Notes:
- Smart Excerpts are applied to titles only in search results.
- The
the_titlefilter is called for each post displayed on the page. - WPFTS includes an additional check for compatibility with the Gutenberg block editor.