wp_enqueue_scripts Hook in WPFTS

The wp_enqueue_scripts hook is a standard WordPress hook used to enqueue scripts and styles on the frontend of a website. WPFTS uses this hook to add styles for Smart Excerpts and scripts for the Live Search widget.

What WPFTS does when wp_enqueue_scripts is called:

  1. Adding Smart Excerpts Styles: If the Smart Excerpts option (is_smart_excerpts) is enabled in the plugin settings, WPFTS adds styles necessary for formatting excerpts in search results. Instead of using wp_enqueue_style(), styles are added directly through a <style> tag, which can make them difficult to override. It is recommended to use the standard method of enqueuing styles via wp_enqueue_style() for better compatibility.

  2. Enqueuing Scripts and Styles for the Live Search Widget: WPFTS enqueues the scripts and styles needed for the Live Search widget, which provides autocomplete functionality when entering a search query. The wp_enqueue_style() and wp_enqueue_script() functions are used, specifying dependencies and version numbers.

Important Functions Involved in Handling wp_enqueue_scripts:

  • WPFTS_Core::get_option()
  • WPFTS_Core::ReadSEStylesMinimized()
  • wp_enqueue_style() (for the Live Search widget)
  • wp_enqueue_script() (for the Live Search widget)

How to Use This in Addon Development:

Addon developers can use this hook to enqueue their scripts and styles needed for working with WPFTS. It’s important to remember that Smart Excerpts styles are added directly via a <style> tag, so to override them, it’s recommended to use the wpfts_se_output filter. To enqueue scripts and styles related to the Live Search widget, you can use the standard WordPress functions wp_enqueue_script() and wp_enqueue_style().

Additional Notes:

  • Smart Excerpts styles are only added to search results pages.
  • Live Search widget scripts and styles are added to all pages where the widget is used.
  • It is recommended to uncomment the line with wp_enqueue_style() for Smart Excerpts in the plugin code and use the standard method of enqueuing styles.