facetwp_assets
Overview
With this hook, you can control which FacetWP JavaScript and CSS files are rendered.
Note that FacetWP intentionally does not use WP enqueue or dequeue functions. Assets are only loaded when facets are detected on the page, which cannot be done using wp_enqueue_script()
or wp_enqueue_style()
.
Parameters
- $assets | array | An associative array of assets to load
Usage
Add a custom JavaScript file to facet pages:
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_assets', function( $assets ) { $assets['custom.js'] = 'URL/TO/YOUR/custom.js'; return $assets; });
To remove an existing asset, you can use the following code. For all available asset keys, see the overview 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
add_filter( 'facetwp_assets', function( $assets ) { unset( $assets['event-manager.js'] ); return $assets; });
Remove FacetWP’s CSS styles
If you want to remove FacetWP’s front-end CSS styles entirely, for example to style your facets entirely from scratch, you can remove front.css
like this:
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_assets', function( $assets ) { unset( $assets['front.css'] ); return $assets; });
Alternatively, you can use the following filter:
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_load_css', '__return_false' );
Enable accessibility support programmatically
FacetWP’s includes built-in accessibility support. This consists of the accessibility.js
script and a few JSON
settings. While you could enable the script independently with the facetwp_assets
hook, this would not include the needed JSON
.
A better way to enable FacetWP’s built-in accessibility support programmatically, is to add the following to your (child) theme’s functions.php:
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_load_a11y', '__return_true' );
Note that this does not override the setting. If either the setting is enabled, or the above hook returns true
, accessibility support will be enabled.
Enable deprecated JS functions
In FacetWP 3.9, a few deprecated JavaScript methods were removed. If your custom code relies on any of the old methods, add the following hook to resolve issues:
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_load_deprecated', '__return_true' );
Available asset keys
- event-manager.js
- front.css
- front.js
- front-facets.js
- front-deprecated.js
- accessibility.js
- jquery.autocomplete.css
- jquery.autocomplete.js
- flatpickr.css
- flatpickr.js
- fSelect.css
- fSelect.js
- gmaps
- nouislider.css
- nouislider.js
- nummy.js
- edd.js
- query-string.js
- woocommerce.js