get_the_excerpt Hook in WPFTS

The get_the_excerpt hook in WordPress is a filter that allows modification of the post excerpt before it’s displayed on a page. WPFTS utilizes this filter to display Smart Excerpts in search results instead of standard excerpts.

What WPFTS does when get_the_excerpt is called:

  1. Condition Check: WPFTS checks the following conditions:

    • The plugin is active, and the Smart Excerpts option is enabled (is_smart_excerpts).
    • The request is on the search results page (is_search()).
    • The request is not from the admin panel (!is_admin()).
    • The excerpt is displayed inside the WordPress loop, or in a Gutenberg block of type post-excerpt (in_the_loop()).
  2. Applying Smart Excerpts: If the conditions are met, WPFTS creates a WPFTS_Result_Item object for the current post, retrieves the search query using get_search_query(false) (or uses $wpfts_core->forced_se_query if Smart Excerpts were forcibly called) and calls the Excerpt() method. This method generates the Smart Excerpt, which is then returned instead of the standard excerpt.

Important Functions Involved in get_the_excerpt Handling:

  • WPFTS_Core::get_option()
  • is_search()
  • is_admin()
  • in_the_loop()
  • get_search_query()
  • WPFTS_Result_Item::Excerpt()
  • 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 replaces standard excerpts with Smart Excerpts in search results. If your addon also modifies excerpts, ensure your logic doesn’t conflict with WPFTS. You can use the wpfts_se_output filter for finer control over Smart Excerpt display.

Additional Notes:

  • Smart Excerpts are only displayed on search results pages.
  • The get_the_excerpt filter is called for each post displayed on the search results page.
  • WPFTS adds compatibility checks for the Gutenberg block editor.