The HTML element is unfortunately fixed in the source code like this, see: https://github.com/WordPress/WordPress/blob/master/wp-includes/blocks/post-terms.php#L42
I also don’t see a hook to change this.
You still have 3 possibilities:
- Develop a Gutenberg block yourself that creates such a list. Build their output the way you want it.
- Send a request to the Gutenberg team: https://github.com/WordPress/gutenberg/issues
- Leave it as it is. If you are concerned with design, the HTML element does not matter, CSS does. For semantic adjustments this list might have too little meaning I think.
Thank you for answering @threadi
You’re right about the semantic
Finally I wrote a simple str_replace and it works, but I am not sure that it is a ‘clean’ solution (?)
function change_div_to_h2( $block_content ) {
if ( is_home() ) { // here H2
return str_replace('div','h2', $block_content);
}
else { // here DIV
return $block_content;
}
}
add_filter( 'render_block_core/post-terms', 'change_div_to_h2', 10, 1 );
Yes, that’s a good 4th option I hadn’t thought of. The code is basically fine, however I would make a short-exit in case it doesn’t apply. So like this:
function change_div_to_h2( $block_content ) {
if ( !is_home() ) {
return $block_content;
}
// show post-terms as h2 instead of div on home.
return str_replace( 'div', 'h2', $block_content );
}
add_filter( 'render_block_core/post-terms', 'change_div_to_h2', 10, 1 );
Great if I could help. You are welcome to set the topic to solved.