Grow your CSS skills. Land your dream job.

Clean up script tags in WordPress

  • # February 24, 2013 at 3:39 pm

    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

    Isn’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

    Yes, 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 24, 2013 at 5:32 pm

    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)

    # February 25, 2013 at 12:58 am

    You 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

    Big 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

    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 (type="text/javascript" won’t hurt anything), then don’t worry about it.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".