wpfts_widget_instance (Filter)
The wpfts_widget_instance
filter in WP Fast Total Search allows developers to modify the data of the WPFTS search widget instance before it’s displayed. This enables dynamic changes to widget settings, such as the title, placeholder text, button text, and other parameters.
When to Use
This filter can be useful if you need to change the widget settings depending on the context, for example:
- Changing the widget title based on the current page.
- Setting different placeholders for different search types.
- Adding or modifying CSS classes for the widget.
Arguments
$instance
(array): An associative array of widget instance data. Contains keys such astitle
,wpfts_wdgt
,placeholder
,button_text
,hide_button
,class
, etc.$id_base
(string): The widget’s base ID (in this case,wpfts_custom_widget
).
Return Value
$instance
(array): The modified array of widget instance data.
Example (Changing the widget title on a product category page)
add_filter('wpfts_widget_instance', 'change_widget_title', 10, 2);
function change_widget_title($instance, $id_base)
{
if (is_product_category()) {
$instance['title'] = __('Search Products', 'my-theme');
}
return $instance;
}
Important Notes
- The
wpfts_widget_instance
filter is called before the widget is displayed. - Changes made to the
$instance
array will be applied to the displayed widget.
The wpfts_widget_instance
filter gives developers flexibility in customizing the display of the WPFTS search widget depending on the page context.