The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Clean up script tags in WordPress

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #42938

    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?


    Isn’t it best practice to use [wp_enqueue_script]( ?


    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


    You can hard code that in if you wish.

    Just make sure that other plug-ins are not requiring same script.


    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?

    [email protected]

    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.


    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.


    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.


    Excuse 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);


    I 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

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘Back End’ is closed to new topics and replies.