Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save propertyhive/badc60cbd96e1d9c181b7b0ad0964f5b to your computer and use it in GitHub Desktop.
Save propertyhive/badc60cbd96e1d9c181b7b0ad0964f5b to your computer and use it in GitHub Desktop.
add_filter( 'elementor/frontend/widget/before_render', function( $widget )
{
// Only target specific widget types if needed
if ( $widget->get_name() !== 'property-availability' ) {
return;
}
// Get current post ID
$post_id = get_the_ID();
// Get custom taxonomy term
$terms = get_the_terms( $post_id, 'availability' );
if ( is_wp_error( $terms ) || empty( $terms ) ) {
return;
}
// Get first term slug or name
$term_slug = sanitize_title( $terms[0]->name );
// Add attribute to the widget wrapper
$widget->add_render_attribute( '_wrapper', 'data-availability', $term_slug );
}, 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment