Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Created December 12, 2022 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diggeddy/7b6b2ae9da5c5fae75a6065ee684919c to your computer and use it in GitHub Desktop.
Save diggeddy/7b6b2ae9da5c5fae75a6065ee684919c to your computer and use it in GitHub Desktop.
Add Title to widget aside for better A11y
<?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