The page_link
Hook in WPFTS
The page_link
hook in WordPress is a filter that allows modification of a page’s URL before it’s displayed. WPFTS utilizes this filter to apply Smart Excerpts to page links displayed in search results. The logic is practically identical to the attachment_link
filter.
What WPFTS Does When page_link
is Called:
-
Condition Check: WPFTS checks if the following conditions are met:
- 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 link is displayed within the WordPress loop, or in a Gutenberg block displaying a post title (
in_the_loop()
). - Or, if
$wpfts_core->forced_se_query
is not equal tofalse
(forced Smart Excerpts call).
- The plugin is active, and the Smart Excerpts option is enabled (
-
Applying Smart Excerpts to the Link: If all conditions are met, WPFTS creates a
WPFTS_Result_Item
object for the page and calls itsTitleLink()
method, which returns the modified link.
Important Functions Involved in page_link
Processing:
WPFTS_Core::get_option()
is_search()
is_admin()
in_the_loop()
WPFTS_Result_Item::TitleLink()
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 page links in search results when Smart Excerpts are used. If your addon also modifies page links, ensure your logic doesn’t conflict with WPFTS.
Additional Notes:
- Smart Excerpts are applied to page links only in search results.
- The
page_link
filter is called for each page displayed on the search results page. - WPFTS adds an additional check for compatibility with the Gutenberg block editor.