Hook
Modify WP Grid Builder Facet HTML – add a title tag
In this filter we have access to the WP Grid Builder Facet HTML. It allows to perform simple str_replace() operations, or more complex actions, for example, adding a title tag to each facet, so on hover of the facet we can see the current Facet Option data
In this example, it is a Taxonomy facet and we want to display the description of the term as a title.
The Taxonomy is “Our Custom Taxonomy” and facet ID is 2 in the example.
We use the helper function tkt_get_contents to get the several occurrences of the strings to replace.
add_filter( 'wp_grid_builder/facet/html', 'tkt_facet_html', 10, 2 );
function tkt_facet_html( $html, $facet_id ) {
$taxonomy = 'our-custom-taxonomy-slug';
$start = '';//if checkbox, analyse HTML to be sure
$end = ' ';//Usually there is a empty space at the end of label, check HTML to be sure
if ( 2 === (int)$facet_id ) {
$term_names = tkt_get_contents($html, $start, $end);
foreach($term_names as $term_name){
$term = get_term_by( 'name', $term_name, $taxonomy);
$term_desc = trim( strip_tags ( term_description( $term->term_id ) ) );
$html = str_replace( $start . $term_name . $end, '' . $term_name . $end, $html );
}
}
return $html;
}