Remove Extra Attributes From WordPress Theme

Removing extra attributes from WordPress helps to standard the website’s HTML code. This article shows you how to remove extra attributes from your WordPress website code.

How to Remove Extra Attributes From WordPress website code

In WordPress some tags have extra attributes – mostly <rel> and <script> tags. These tags do a specific job. “rel” adds a Style Sheet file to the HTML document and the “Script” tag adds a JavaScript file to the document.

Some attributes of these tags must be removed. These attributes generate errors or warnings in the W3C standard code check.

To remove attributes, add the code below to the functions.php file.

add_action('wp_loaded', 'output_buffer_start');
function output_buffer_start()

function output_callback($buffer)
    return preg_replace("%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer);

This code will remove the “type” attribute which has a “javascript” or “CSS” value. In rel tag removes CSS and in script tag removes javascript.

Shopping Cart