Skip to main content

Forums

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

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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?

    #125824
    snapey
    Member

    Isn’t it best practice to use [wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script) ?

    #125827

    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

    #125886
    Alen
    Participant

    You can hard code that in if you wish.

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

    #151538
    Marcel
    Participant

    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?

    #157469
    [email protected]
    Participant

    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.

    #157471
    Senff
    Participant

    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.

    #157474
    __
    Participant

    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.

    #246425
    LeoNovais
    Participant

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

    #270177
    equippedcreative
    Participant

    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.