- This topic is empty.
-
AuthorPosts
-
February 24, 2013 at 3:39 pm #42938KeithPickeringMember
Wordpress outputs scripts like this:
< script type='text/javascript' src='/path/to/script.js'>
Which forces me to instead call scripts directly from the theme, so they appear like this:
< script src="/path/to/script.js">
I’ve googled high and low and I can’t find anything regarding how to change those single quotes to double quotes and remove the “type” attribute. Any ideas?
February 24, 2013 at 3:52 pm #125824snapeyMemberIsn’t it best practice to use [wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script) ?
February 24, 2013 at 4:03 pm #125827KeithPickeringMemberYes, but I can’t really do that, because that’s what creates the outdated markup in the first place.
And I care about this sort of thing for some reason :P
February 25, 2013 at 12:58 am #125886AlenParticipantYou can hard code that in if you wish.
Just make sure that other plug-ins are not requiring same script.
September 27, 2013 at 2:57 pm #151538MarcelParticipantBig ol’ bump.
I use Roots starter theme and this is one of the only things it doesn’t yet do as part of it’s cleanup helper.
Anyone around now familiar with getting this done?
November 30, 2013 at 6:44 pm #157469[email protected]ParticipantI can be done, but from what I have researched requires modifications to the Core files in WordPress mainly class.wp-scripts.php – in do_item is where they get created.
There is no hook for this function.
It maybe possible to write an extending of the function to remove the type item.
Making changes to the Core files will lead to redoing the changes to them or loosing the changes on an update.
November 30, 2013 at 8:24 pm #157471SenffParticipantI used to do this as well, just to end up with code that’s as clean as possible. But, in the end it just took too much time (and editing code in WP core), and it just wasn’t worth all the effort. It’s not bad or dirty code — it’s just a little different than what I would like to see.
I just learned to live with it, or perhaps I just stopped caring about something as trivial as this.
November 30, 2013 at 9:39 pm #157474__ParticipantI’ll second that. I once decided to refactor a cms (I think it was Concrete5) to output html4.01 strict instead of xhtml… I worked on it for three weeks, completely broke the system a dozen times, and eventually decided it didn’t really matter. Either use something the way it was designed, or make your own.
If WP is outputting valid, cross-browser markup (
type="text/javascript"
won’t hurt anything), then don’t worry about it.October 11, 2016 at 3:59 pm #246425LeoNovaisParticipantExcuse my English, but this stretch worked well for me
add_filter('script_loader_tag', 'clean_script_tag');
function clean_script_tag($input) {
$input = str_replace("type='text/javascript' ", '', $input);
return str_replace("'", '"', $input);
}
April 24, 2018 at 8:16 am #270177equippedcreativeParticipantI wanted to add a note to this post letting people know that this now breaks Gutenberg. When I had this in my theme functions.php and tried to add a new page/post, I got the following error: TypeError: Cannot read property ‘routes’ of undefined
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.