本文介绍了如何将aria标签分配到侧边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Siteimprove的chrome扩展程序浏览客户的网站,以测试其合规性.我在一个侧边栏区域的两个助手上收到具有相同名称的地标"错误.在functions.php中的注册侧边栏代码中,我具有:

I'm going through a client's site using Siteimprove's chrome extension to test for compliance. I'm getting a "Landmarks with identical names" error on two asides in one sidebar area. In the register sidebar code in functions.php, I have:

'before_widget' => '<aside id="%1$s" class="widget %2$s" aria-label="Job Openings and Events">',

这正在工作并分配标签,但是此侧栏中有两个小部件(一个文本小部件和事件列表小部件),而Wordpress则为每个具有相同标签的小部件创建一个一边.是否有某种第n种分配,或者我可以做一些事情来为该边栏中的每一个分配不同的标签,以防止冗余?

This is working and assigning the label, but there are two widgets in this sidebar (a text widget and events list widget) and Wordpress is creating an aside for each with the same label. Is there some sort of nth assignment or something I can do to assign each aside in this sidebar with a different label to prevent redundancy?

推荐答案

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

Use this solution it will add aria-label in all the widgets

这篇关于如何将aria标签分配到侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 06:43