Le immagini inserite tramite l'editor di WordPress possono essere rese compatibili con lo standard HTML5 utilizzando gli elementi figure
e figcaption
. Quello che dobbiamo fare è intercettare l'hook di WordPress che inserisce le immagini prese dalla Media Library nell'editor.
Aggiungete il seguente codice al file functions.php
:
function html5_insert_image($html, $id, $caption, $title, $align, $url) {
$html5 = "<figure id='post-$id media-$id' class='align-$align'>";
$html5 .= "<img src='$url' alt='$title' />";
if ($caption) {
$html5 .= "<figcaption>$caption</figcaption>";
}
$html5 .= "</figure>";
return $html5;
}
add_filter( 'image_send_to_editor', 'html5_insert_image', 10, 9 );