Remove type= from site code for WordPress CMS

When checking the site with the W3C validation service, warnings may appear due to the fact that the scripts and stylesheets have the attributes type='text/css' and type='text/javascript' in the code. They may appear due to plugins that use this syntax when connecting + the WordPress engine itself can post them.

To remove these attributes and avoid warnings, when checking, you can write a function in functions.php your theme that will remove them from the code.

add_filter('style_loader_tag', 'clean_style_tag'); /* Add a function to the style_loader_tag hook that will remove the type='text/css' attribute */
function clean_style_tag($src){
    return str_replace("type='text/css'", "", $src);

add_filter('script_loader_tag', 'clean_script_tag'); /* Add a function to the script_loader_tag hook that will remove the type='text/javascript' attribute */
function clean_script_tag($src){
    return str_replace("type='text/javascript'", "", $src);

add_action('wp_loaded', 'buffer_start'); /* We enable output buffering to call the function to remove type='text/css' and type='text/javascript' from the code */
function buffer_start(){ 

add_action('shutdown', 'buffer_end'); /* Turn off output buffering */
function buffer_end(){ 

function callback($buffer){ /* Function to delete type='text/css' and type='text/javascript' */
    return preg_replace("%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", "", $buffer);


If you have any questions, want to get individual advice or you have an interesting offer, you can contact via the feedback form.

Or write to the email

By submitting the form, you agree to our privacy policy