' . $matches[3] . $matches[4]; endif; return $matches[0]; }, $content ); return $content; } add_filter( 'the_content', 'auto_id_headings' );"> ' . $matches[3] . $matches[4]; endif; return $matches[0]; }, $content ); return $content; } add_filter( 'the_content', 'auto_id_headings' );"> ' . $matches[3] . $matches[4]; endif; return $matches[0]; }, $content ); return $content; } add_filter( 'the_content', 'auto_id_headings' );">
/**
* Automatically add IDs to headings such as <h2></h2>
*/
function auto_id_headings( $content ) {
$content = preg_replace_callback( '/(\\<h[1-6](.*?))\\>(.*)(<\\/h[1-6]>)/i', function( $matches ) {
if ( ! stripos( $matches[0], 'id=' ) ) :
$matches[0] = $matches[1] . $matches[2] . ' id="' . sanitize_title( $matches[3] ) . '">' . $matches[3] . $matches[4];
endif;
return $matches[0];
}, $content );
return $content;
}
add_filter( 'the_content', 'auto_id_headings' );
Info: Ive collected this code snippet and dont know the author anymore. If you are the author, please write me a message and i will give you a credit.