WordPress

w3c error fixes

#w3c : Trailing slash on void elements 
function fix_trailing_slash( $content ) {
    if ( ! is_admin() ) {
        $pattern = '/<(img|meta|link|input|br)\b([^>]*)\/>/i';
        $content = preg_replace( $pattern, '<$1$2>', $content );
    }
    return $content;
}
function apply_fix_trailing_slash() {
    ob_start( 'fix_trailing_slash' );
}
add_action( 'wp_head', 'apply_fix_trailing_slash', 1 );
add_action( 'wp_footer', 'apply_fix_trailing_slash', 1 );
add_filter( 'the_content', 'fix_trailing_slash', 11 );


# w3c : Remove role="button"
function remove_button_role_attribute( $content ) {
    $pattern = '/<button\b(.*?)role=["\']button["\'](.*?)>/i';
    $content = preg_replace( $pattern, '<button$1$2>', $content );
    return $content;
}
function remove_button_role_from_sections() {
    ob_start( 'remove_button_role_attribute' );
}
add_action( 'wp_head', 'remove_button_role_from_sections', 1 );
add_action( 'wp_footer', 'remove_button_role_from_sections', 1 );
add_filter( 'the_content', 'remove_button_role_attribute', 11 );