Remove type='text/javascript' from contact form 7 tags

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Remove type='text/javascript' from contact form 7 tags



I removed most of the type attributes from my wordpress site but still I can see this on the contact form 7 tags, how do I remove them?



I was searching this on google but didn't find the solution. Please help!



Note: I am validating html on validator.w3.org it gives warning, please see below.


Warning: The type attribute is unnecessary for JavaScript resources.





Why would you need to remove the type attributes?
– Brainfeeder
Aug 6 at 14:12





I am getting warning on Validator.w3.org
– Yasir Khan
Aug 6 at 14:13





Please note these are just warnings, your code will be valid (in case you don't have any other errors). The validator is used for educational purpose but is far from a global base of doing stuff :) You might find what you want here: wordpress.stackexchange.com/questions/287830/… Seems more WP sites suffer from this 'issue'.
– Brainfeeder
Aug 6 at 14:17





It's a warning. "unnecessary" is not "forbidden". Why worry about it?
– Quentin
Aug 6 at 14:17






I do hope they will not ban the use of the type attribute because our apps rely on that to know what to do with the codeblock when it was fetched togheter with a partial view file...
– Brainfeeder
Aug 6 at 14:21




2 Answers
2



You've mentioned that your client wants these tags removed. I assume you've explained to him that they're benign (and arguably sometimes helpful). Barring that, if you still need to remove these tags, you can just use a "run time replace" instead of trying to find every. single. instance. of a script that has that attribute, especially if one plugin or another doesn't enqueue scripts properly.



Take this function for instance:


add_action( 'template_redirect', function()
ob_start( function( $buffer )
$buffer = str_replace( array( 'type="text/javascript"', "type='text/javascript'" ), '', $buffer );

return $buffer;
);
);



The template_redirect hook effectively has access to all of the markup for the page. So you can instead just add it to an Output Buffer, run a simple str_replace on it, and return that output.


template_redirect


str_replace



You'll notive I've added both quote notation types since either could be in your source code at some point. You could use a regex for it if you wanted, but the array of both notations should suffice.





Works like a charm, you've explained it well also.
– Yasir Khan
Aug 7 at 14:31





My pleasure! Just a note: My initial thought was similar to @Riad Citaku's answer below - however there are many plugins that add scripts improperly and thus could be missed by filtering the script_loader_tag. It seems your client is adamant to have the tag removed so this solution is kind of the "use a hammer to kill a fly" kind of solution
– Xhynk
Aug 7 at 16:42


script_loader_tag



This is how you remove type="text/javascript" from all JavaScript files with the WordPress filter script_loader_tag.


type="text/javascript"


script_loader_tag


add_filter('script_loader_tag', 'your_slug_remove_type_attr', 10, 2);
function your_slug_remove_type_attr($tag, $handle)
return preg_replace("/type=['"]text/(javascript)['"]/", '', $tag);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard