Created
December 12, 2022 11:39
-
-
Save diggeddy/7b6b2ae9da5c5fae75a6065ee684919c to your computer and use it in GitHub Desktop.
Add Title to widget aside for better A11y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function db_add_widget_title_attr($params) { | |
// get the widget ID | |
$id = $params[0]['id']; | |
// get the widget name | |
$name = isset($params[0]['widget_name']) ? $params[0]['widget_name'] : ""; | |
// create a new aside html string with concatenated name + id title attribute | |
$title = '<aside title="' . $name . ' ' . $id . '"'; | |
// string replace the before widget opening tag | |
$params[0]['before_widget'] = str_replace( '<aside' , $title , $params[0]['before_widget'] ); | |
return $params; | |
} | |
add_filter('dynamic_sidebar_params', 'db_add_widget_title_attr'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment