1 year ago
<?php
/**
* add labels above facets by changing shortcode output
* this will apply to all facets except $exclude_types set below
* change or remove conditional to apply this to whichever facets needed
* wrapper can also be added
*/
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( isset( $atts["facet"] ) && '' != $atts["facet"] ) { // check for facet shortcode
$exclude_types = [ 'sort', 'reset', 'pager', 'map' ]; // set facet types to exclude from labels
$facet = FWP()->helper->get_facet_by_name( $atts["facet"] ); // get facet settings
if ( !in_array( $facet["type"], $exclude_types ) ) { // conditional to exclude types in $exclude_types
$output = '<h3 class="facet-label">' . $facet["label"] . '</h3>' . $output; // prepend with label and markup
// uncomment below to add facet-wrap
// $output = '<div class="facet-wrap">' . $output . '</div>';
}
}
return $output;
}, 10, 2 );
9 months ago
<?php
// https://www.w3.org/WAI/WCAG21/Understanding/status-messages.html
// with a working example at:
// https://www.w3.org/WAI/WCAG22/working-examples/aria-role-status-searchresults/
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( isset( $atts['facet'] ) && 'pager_resultcounts' == $atts['facet'] ) { // Change "pager_resultcounts" to the name of your Pager facet
$output = str_replace( 'data-name', 'role="status" data-name', $output );
}
return $output;
}, 10, 2 );
9 months ago
<?php
// Add an aria-live=”polite” attribute to the <div> with class "facetwp-template", generated by a Listing Builder listing template.
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( isset( $atts['template'] ) ) {
$output = str_replace( 'class="facetwp-template"', 'class="facetwp-template" aria-live="polite"', $output );
}
return $output;
}, 10, 2 );
3 years ago
/**
** adds is-hidden class to facetwp template to initial hide template.
** for use with conditional logic addon to show/hide template with
** conditions, prevents flash of content when hidden is the initial
** state
**/
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( isset( $atts['template'] ) && 'my_template' == $atts['template'] ) { // change my_template to match your template
$output = str_replace( 'class="facetwp-template"', 'class="facetwp-template is-hidden"', $output );
}
return $output;
}, 10, 2 );
6 years ago
<?php
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( isset( $atts['template'] ) ) {
$output = str_replace( 'facetwp-template', 'facetwp-template row', $output );
}
return $output;
}, 10, 2 );
6 years ago
<?php
/** changes <div class="facetwp-template" in facetwp template shortcode output to a ul
** will not work if facetwp_use_pager_seo is true
**/
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {
if ( !empty( $atts['template'] ) && 'example' == $atts['template'] ) { // change "example" to your template name
$output = str_replace( '<div class="facetwp-template"', '<ul class="facetwp-template"', $output );
$output = substr_replace( $output, '</ul>', -6 );
}
return $output;
}, 10, 2 );
6 years ago
<?php
/** add additional classes / id to the facetwp-template div generated by a facetwp
** layout template
**/
add_filter( 'facetwp_shortcode_html', function( $output, $atts) {
if ( $atts['template'] = 'example' ) { // replace 'example' with name of your template
/** modify replacement as needed, make sure you keep the facetwp-template class **/
$output = str_replace( 'class="facetwp-template"', 'id="masonry-container" class="facetwp-template small-up-1 medium-up-2 large-up-3"', $output );
}
return $output;
}, 10, 2 );