I am working on WordPress Site,these warnings are coming on every single page, Is there any method to resolve this.
Warning:The type attribute is unnecessary for JavaScript resources.
<script type="text/javascript">
I am working on WordPress Site,these warnings are coming on every single page, Is there any method to resolve this.
Warning:The type attribute is unnecessary for JavaScript resources.
<script type="text/javascript">
Add following code to your theme's functions.php
add_action( 'template_redirect', 'prefix_remove_template_redirect', 10, 2);
function prefix_remove_template_redirect(){
ob_start( function( $buffer ){
$buffer = str_replace( array(
'<script type="text/javascript">',
"<script type='text/javascript'>",
"<script type='text/javascript' src=",
'<script type="text/javascript" src=',
'<style type="text/css">',
"' type='text/css' media=",
'<style type="text/css" media',
"' type='text/css'>"
),
array(
'<script>',
"<script>",
"<script src=",
'<script src=',
'<style>',
"' media=",
'<style media',
"' >"
), $buffer );
return $buffer;
});
};
This will change <script type="text/javascript"> to <script> And will change <style type="text/css"> to <style>. It can be done by script_loader_tag but it’s given theme check validation error.
Update: From WordPress 5.3, You can use following.
function theme_name_setup() {
add_theme_support( 'html5', array( 'script', 'style' ) );
}
add_action( 'after_setup_theme', 'theme_name_setup' );
8798 from function's name. it works for me. thanks @JahirulIslamMamunAdd the below code to your theme's functions.php
add_filter('script_loader_tag', 'clean_script_tag');
function clean_script_tag($input) {
$input = str_replace("type='text/javascript' ", '', $input);
return str_replace("'", '"', $input);
}
This will change <script type="text/javascript"> to <script> for the plugin loaded scripts.
And then change <script type="text/javascript"> to <script> in your theme's header an footer php files.
i added two things. This works for me:
#one for JS mime-type
add_action( 'template_redirect', function(){
ob_start( function( $buffer ){
$buffer = str_replace( array( 'type="text/javascript"', "type='text/javascript'" ), '', $buffer );
return $buffer;
});
});
#one for CSS-Mime-Type
add_action( 'template_redirect', function(){
ob_start( function( $buffer ){
$buffer = str_replace( array( 'type="text/css"', "type='text/css'" ), '', $buffer );
return $buffer;
});
});
I know you can do both in one function, but here can you decide for oneself what you want (JS or CSS or both)