Clean up script tags in WordPress
# February 24, 2013 at 3:39 pm
Wordpress outputs scripts like this:
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
Isn’t it best practice to use [wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script) ?# February 24, 2013 at 5:32 pm
This reply has been reported for inappropriate content.
I care about those things too, but don’t have experience with WP. Can’t you trace the php back to where it actually creates this output and fix it there? (Not the best solution obviously, since updating WP will just overwrite your changes, but don’t ask me how to make a module or plugin for WP that overwrites default behavior)# November 30, 2013 at 6:44 pm
I 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
I 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
I’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 (
You must be logged in to reply to this topic.