Skip to content

Instantly share code, notes, and snippets.

@JiveDig
Created August 8, 2019 19:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiveDig/43567bc161e4873c29b9c9e6791d6170 to your computer and use it in GitHub Desktop.
Save JiveDig/43567bc161e4873c29b9c9e6791d6170 to your computer and use it in GitHub Desktop.
Automatically add facet label as a heading before any facets with available options to filter by.
<?php
/**
* Adds facet label as a heading before any facets with available options.
*
* @author Mike Hemberger @JiveDig.
*
* @param string $output The facet HTML.
* @param array $params The shortcode/function parameters.
*
* @return string The modified output.
*/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
// Bail if no facet options.
if ( empty( $params['values'] ) ) {
return $output;
}
// Return label as heading.
return sprintf( '<h3>%s</h3>%s', $params['facet']['label'], $output );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment