Custom Attributes for Post Widget
The plugin provides filters to customize HTML attributes on the wrapper and individual posts in the Posts widget. You can add classes, IDs, data attributes, and ARIA attributes programmatically, scoped by the widget’s Query ID.
Hook Details
Hook Type |
Filter Hook |
Hook Names |
bpfwe/post_wrapper_attr/{$query_id}
bpfwe/post_wrapper_inner_attr/{$query_id}
bpfwe/post_attr/{$query_id} |
Affects |
HTML attributes for wrapper, inner wrapper, and post containers |
Hook Arguments
Argument |
Type |
Description |
attributes |
array |
Associative array of attributes (class , id , data-* , etc.) |
widget |
\Elementor\Widget_Base |
The widget instance rendering the posts |
context |
string |
Context string: wrapper , inner , or post |
Using the Custom Filter
add_filter( 'bpfwe/post_wrapper_attr/{$query_id}', function( $attributes, $widget, $context ) {
// Modify attributes here
return $attributes;
}, 10, 3 );
Examples
Example 1: Add Custom Classes and ID to Wrapper
add_filter( 'bpfwe/post_wrapper_attr/my_custom_query', function( $attributes, $widget, $context ) {
$attributes['class'][] = 'custom-wrapper extra-style';
$attributes['id'] = 'wrapper-id';
return $attributes;
}, 10, 3 );
Example 2: Add Data Attributes to Inner Wrapper
add_filter( 'bpfwe/post_wrapper_inner_attr/my_custom_query', function( $attributes, $widget, $context ) {
$attributes['data-filter'] = 'category-2';
$attributes['aria-label'] = 'Custom Widget';
return $attributes;
}, 10, 3 );
Example 3: Highlight Specific Posts
add_filter( 'bpfwe/post_attr/my_custom_query', function( $attributes, $widget, $context ) {
$post_id = get_the_ID();
$attributes['class'][] = 'single-post highlight-' . $post_id;
$attributes['data-post-type'] = 'featured';
$attributes['aria-hidden'] = 'true';
return $attributes;
}, 10, 3 );
Notes
- Replace
my_custom_query
with your actual Query ID.
- get_the_ID() retrieves the current post ID in
bpfwe/post_attr/
- All attributes are automatically escaped before output.
- Multiple classes can be added by pushing into the
class
array.
- These hooks allow integration with CSS, JS, or accessibility enhancements.
Custom Filter for Term Queries
When retrieving taxonomy terms for the filter, the plugin lets you modify the get_terms()
arguments programmatically. Useful for excluding terms, adjusting order, or adding custom conditions beyond the available widget options.
Hook Details
Hook Type |
Filter Hook |
Hook Name |
bpfwe/get_terms_args/{$query_id} |
Affects |
Taxonomy Term Queries |
Hook Arguments
Argument |
Type |
Description |
args |
array |
The arguments array passed to get_terms() . You can modify or extend these. |
widget |
\Elementor\Widget_Base |
The widget instance triggering the query. |
Setting Up a Custom Filter
Assign a unique Query ID under Content > Additional Options > Filter Query ID
. For example, if you use my_filter
, the hook is bpfwe/get_terms_args/my_filter
.
Using the Custom Filter
add_filter( 'bpfwe/get_terms_args/{$query_id}', function( $args, $widget ) {
// Modify the get_terms args here
return $args;
}, 10, 2 );
Examples
Example 1: Exclude Terms
add_filter( 'bpfwe/get_terms_args/my_filter', function( $args, $widget ) {
$args['exclude'] = [ 14294, 14292 ];
return $args;
}, 10, 2 );
Example 2: Show Empty Terms Only for Logged-in Users
add_filter( 'bpfwe/get_terms_args/my_filter', function( $args, $widget ) {
if ( is_user_logged_in() ) {
$args['hide_empty'] = false;
}
return $args;
}, 10, 2 );
Example 3: Filter Terms Based on Current Page
add_filter( 'bpfwe/get_terms_args/my_filter', function( $args, $widget ) {
if ( is_category() || is_tag() ) {
$current_term = get_queried_object();
if ( $current_term && ! is_wp_error( $current_term ) ) {
$args['include'] = [ $current_term->term_id ];
}
} elseif ( is_singular( 'post' ) ) {
global $post;
$args['include'] = wp_get_post_terms( $post->ID, 'category', [ 'fields' => 'ids' ] );
}
return $args;
}, 10, 2 );
Notes
- Replace
my_filter
with your actual Query ID.
- Refer to get_terms for available arguments.