Documentation / Hooks

Hooks

Hooks

Filter term name hooks

Allow to change filter’s term html in Filter widget.

/* Post meta term name */
apply_filters('wpc_filter_post_meta_term_name', $term_name,  $entity_name);
/* Post meta exists term name */
apply_filters('wpc_filter_post_meta_exists_term_name', $term_name,  $entity_name);
/* Post meta num term name */
apply_filters('wpc_filter_post_meta_num_term_name', $term_name,  $entity_name);
/* Taxonomy term name */
apply_filters('wpc_filter_taxonomy_term_name', $term_name,  $entity_name);
/* Author term name */
apply_filters('wpc_filter_author_term_name', $term_name,  $entity_name);

Usage Example

/**
 * Let's capitalize all terms for Product type 
 * and Product visibility
 */
add_filter('wpc_filter_taxonomy_term_name', 'wpc_modify_taxonomy_term_name', 10, 2 );
function wpc_modify_taxonomy_term_name($term_name, $e_name)
{
    if (in_array($e_name, array('product_type', 'product_visibility'))) {
        $term_name = ucfirst($term_name);
    }
    return $term_name;
}

Parameters

  • $term_name (string) Term name
  • $entity_name (string) Term entity name ( taxonomy name, author or post meta key )

Filter term html hooks

Allow to change filter term html in Filters widget.

/* Checkbox term html */
apply_filters( 'wpc_filters_checkbox_term_html', '<a '.$link_attributes.'>'.$term_object->name.'</a>', $link_attributes, $term_object, $filter );
/* Label term html */
apply_filters( 'wpc_filters_label_term_html', '<a '.$link_attributes.'>'.$term_object->name.'</a>', $link_attributes, $term_object, $filter );
/* Radio term html */
apply_filters( 'wpc_filters_radio_term_html', '<a '.$link_attributes.'>'.$term_object->name.'</a>', $link_attributes, $term_object, $filter );

Usage Example

/* Let's add Apple logo for 'apple' brand term */
add_filter( 'wpc_filters_checkbox_term_html', 'wpc_term_brand_logo', 10, 4 );
function wpc_term_brand_logo($html, $link_attributes, $term, $filter){
    if( $term->slug === 'apple' ){
        $img  = '<img src="'.plugin_dir_url(__FILE__).'/img/apple.svg" alt="Apple logo" width="15" height="15" />';
        $html = '<a '.$link_attributes.'>'.$img . ' '. $term->name.'</a>';
    }
    return $html;
}

Parameters

  • $html (string) Term html
  • $link_attributes (string) Term link attributes
  • $term (object) Term object
  • $filter (array) Filter parameters

Terms filter before display

Allows to modify terms list before displaying them in the widget.

$terms = apply_filters( 'wpc_terms_before_display', $terms, $filter, $set, $urlManager );

Usage Example

/* Let's sort Color filter terms by the menu_order */
add_filter('wpc_terms_before_display', 'wpc_sort_terms_as_needed', 10, 2);
function wpc_sort_terms_as_needed($terms, $filter){
    // pa_color - is desired taxonomy
    if ($filter['e_name'] === 'pa_color') {
        $newTerms = [];
        foreach ($terms as $k => $term) {
            $termOrder = get_term_meta($term->term_id, 'order', true);
            $term->menu_order = ($termOrder !== false) ? $termOrder : 0;
            $newTerms[$k] = $term;
        }

        // To sort in descending order
        // usort( $newTerms, \FilterEverything\Filter\EntityManager::compareDesc('menu_order') );
        // To sort in ascending order
        usort($newTerms, \FilterEverything\Filter\EntityManager::compareAsc('menu_order'));

        return $newTerms;
    }

    return $terms;
}

Parameters

  • $terms (array) List of term objects
  • $filter (array) Current Filter parameters
  • $set (array) Filter Set fields with parameters
  • $urlManager (object) Of the UrlManager Class, that can be used to get the link to the filter

SEO var filter

Allows to change SEO var value. Works for all SEO var values: SEO title, Meta description, H1 title, Page description.

apply_filters( 'wpc_seo_var_term_name', $term_name, $entity_name );

Usage Example

Before applying this code H1 title was “Buy apple smartphones in Paris”
After applying became “Buy Apple smartphones in Paris”

/* Let's capitalize Brand SEO vars */
add_filter('wpc_seo_var_term_name', 'wpc_uppercase_brand_seo_vars', 10, 2);
function wpc_uppercase_brand_seo_vars( $term_name, $entity_name )
{
    if( 'brand' === $entity_name ){
        return ucfirst($term_name);
    }

    return $term_name;
}

Parameters

  • $term_name (string) Term name
  • $entity_name (string) Term entity name ( taxonomy name, author or post meta key )

Auto Scroll offset

Allows you to change the position to which the Auto scroll is scrolled.

apply_filters( 'wpc_auto_scroll_offset', 150 );

Usage Example

add_filter('wpc_auto_scroll_offset', 'wpc_change_auto_scroll_offset');
function wpc_change_auto_scroll_offset( $offset ){
    return 200;
}

Parameters

  • $offset (int) Scroll offset in pixels from the top of posts container

Make your filtering best with