0

When trying to edit a wordpress post (page) the editor loads indefinitely, console shows JS error with post.php / polyfill, see code below. To me it seems to be a typo and I have no idea where the line is injected so I could change it manually.

Disabling all plugins did not change anything, neither did disabling Gutenberg. I am not much of a coder, nevertheless it seems to me there should not be a double quotation mark after the last 'defer"... in the line of code.

I am running WP 5.0.2 on Apache (Domainfactory) in a managed server environment, Theme is Enfold by Kriesi. Re-installing Wordpress and the theme (copied from working installations) changed nothing so far.

The reported error in the console is "Uncaught SyntaxError: missing ) after argument list" in https://.../wp-admin/post.php?post=23&action=edit&lang=de&classic-editor=1:238

There it says

( 'fetch' in window ) || document.write( '<script src="https://12345678-123.ch/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js?ver=3.0.0' defer='defer"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src="https://12345678-123.ch/wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js?ver=3.26.0-0' defer='defer"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src="https://12345678-123.ch/wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js?ver=3.0.12' defer='defer"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src="https://12345678-123.ch/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js?ver=2.0.2' defer='defer"></scr' + 'ipt>' );

Any idea would be much appreciated.

  • ask at: s.tk/wp – T.Todua Jan 4 at 15:12
  • I am sorry. What does that mean? – Amanahumpa Jan 4 at 15:14
  • Thank you for editing and prividing a real resource. Your link sends me to the WP Core bug tracker and there it says it has to be a WP core bug, which is unsure. Moreover I can not wait for the next wordpress update to edit the existing pages I hope to get direction and inspiration here. To file a ticket is another step in the process. Please allow me to get help here. – Amanahumpa Jan 4 at 15:34
  • Did you try changing themes? Not just disabling plugins but also changing the theme? If that solves the issue, then you know it's the theme. – disinfor Jan 4 at 15:37
  • Yes, I did. When using a standard theme and standard editor it works but is of no use since it depends on the integrated page builder ('advanced layout editor'). Dev of the theme has no reports on that so far. I am using the exact same combo of WP / theme / Hoster on other projects. No probs there... :-/ My hope is a workaround until the dev teams can react to that. – Amanahumpa Jan 4 at 15:46
0

Here is an answer: WordPress v5.0.3 Gutenberg & JS error "Uncaught SyntaxError: missing ) after argument list"

The simplest way: Find & delete PHP Hook which added 'defer' to script (in the function.php file). Or if you have skills you can edit the code of the hook. Reason: Confusion/conflict with quotes (' & ") witch break down JS.

About 'defer' you can read here: https://www.w3schools.com/tags/att_script_defer.asp This is probably due to speed optimization on your website.

  • Thanks for the part about the functions.php. This did the trick. – Amanahumpa Mar 31 at 12:59
0

OK, so I struggled to find an answer myself to this - but this worked for me. I was stripping out the type='text/javascript' on script tags because it's not required for valid HTML5 - but WordPress insists on including it when you enqueue_script. I had a function in my theme like below to deal with this - so I just stopped it running in admin and it removed the error - your mileage may vary but maybe check your theme or plugins for something similar ;)

/**
 *
 * WordPress insists on inserting invalid javascript script tag definitions when enqueuing
 * This removes this cruft - to check in the future - will WordPress get patched to support this?
 *
 */
add_filter( 'script_loader_tag', 'mywfx_html5_clean_js_tags' );
function mywfx_html5_clean_js_tags( $input ) {

 if ( !is_admin() ) {

    $input = str_replace( "type='text/javascript' ", '', $input );
    return str_replace( "'", '"', $input );

 } else {

    return $input;

 }

}
  • How is this related to the problem in the question? – fuxia Mar 29 at 14:56
  • I have the inpression this answer is about checking for injections and/or string replacements, thus actually related to the ptoblem stated. At least to the embarassing solution :-/ – Amanahumpa Mar 31 at 12:57
  • @fuxia - this is relevant because the OP could not track down what was causing the issue. I was explaining that in my case the error that they were experiencing (same as me) was being caused by code that could be in a custom theme functions - therefore relevant! – Jonnyauk Apr 5 at 8:58
0

Maybe the lesson to be learnt from injected code is: Check all potencial sources of code injection.

It turned out there was code put in the child themes' functions.php. At the time the question was asked it was as "unnessessary" to look for the problem there as it was dumb not to do that.

I am sorry and grateful for the help provided. Thank you.

  • Good to hear you tracked it down! – Jonnyauk Apr 5 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.