Wordpress

Eliminar atributo type de javascript y CSS en Wordpress

Una de las advertencias más comúnes en el validador de la W3C es :

  • The type attribute is unnecessary for JavaScript resources
  • The type attribute for the style element is not needed and should be omitted.

Esto se debe a que ya no es necesario utilizar el atributo type <style type="text/css"> o <script type="text/javascript">en nuestro código.

Recordar que esto es sólo una advertencia, no un eroor. En el caso que queramos solucionar esta advertencia en un sitio web de Wordpress, vamos al archivo functions.php de nuestro theme activo y añadimos el siguiente código:

add_action('wp_loaded', 'output_buffer_start');
function output_buffer_start() { 
    ob_start("output_callback"); 
}
add_action('shutdown', 'output_buffer_end');
function output_buffer_end() { 
 if (ob_get_length() > 0) { ob_end_clean();}
 }
function output_callback($buffer) {
    return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer );
}

Lo que hará este código, será eliminar el atributo type y no poner nada en su lugar.

Publicaciones relacionadas

Botón volver arriba