Overview

This filter lets you modify a facet’s HTML output.

Parameters

  • $output | string | The facet HTML
  • $params | array | An associative array of facet settings (see below)

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

$params = [ 'facet' => [ 'name' => 'my_facet', 'type' => 'checkboxes', 'source' => 'tax/category', // any other facet-specific settings ], 'values' => [], // available for checkbox & dropdown facets 'selected_values' => [ 100, 101 ] ];

Usage

Add a “form-control” CSS class to all dropdown facets:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_facet_html', function( $output, $params ) { if ( 'dropdown' == $params['facet']['type'] ) { $output = str_replace( 'facetwp-dropdown', 'facetwp-dropdown form-control', $output ); } return $output; }, 10, 2 );

More examples

See also