I am relatively new to Wordpress and using custom filters and hooks.
My site uses the TablePress
plugin. But I need to be able to add the html attribute of
role=presentation
To all tables created through the plugin. The only way to do so is to
There’s not direct way to add this, but you could e.g. use the tablepress_table_tag_attributes filter hook that can be used to change the attributes of the element. The filter is defined in class-render.php
as per https://wordpress.org/support/topic/table-role/#post-9665599
The class-render.php
mentioned is below:
$table_attributes = apply_filters( 'tablepress_table_tag_attributes', $table_attributes, $this->table, $this->render_options );
$table_attributes = $this->_attributes_array_to_string( $table_attributes );
https://github.com/TobiasBg/TablePress/blob/master/classes/class-render.php#L519
In my functions.php
file I have added:
add_filter( 'tablepress_table_tag_attributes' , 'add_presentation_role', 11);
function add_presentation_role() {
// return ?
}
But i am struggling to see what I need to put inside my function. Anything I put in breaks my website or results in a blank page. To confirm I would like to add the the role attribute so my tables update from
<table id="tablepress-{ID}" class="tablepress tablepress-id-{ID}">
to
<table id="tablepress-{ID}" class="tablepress tablepress-id-{ID}" role="presentation">