register_sidebar(array(
'name' => 'Footer #2',
'id' => 'footer2',
'description' => 'Footer widget 2',
'before_widget' => '<aside role="complementary" id="%1$s" class="widget-content footer-widget" aria-label="[title]">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title footer-widget-title">',
'after_title' => '</h2>' ,
));
function stp_accessibility_widget_func($params) {
$name = isset($params[0]['widget_name']) ? $params[0]['widget_name'] : "";
$params[0]['before_widget'] = str_replace('[title]', esc_attr($name), $params[0]['before_widget'] );
return $params;
}
add_filter('dynamic_sidebar_params', 'stp_accessibility_widget_func');
使用此解决方案,它将在所有小部件中添加 aria-label