Laszlo from Nextend did an amazing job and analyzed why Pascal’s plugin causes the issues. Here is his solution, which I tried and it works:
——————-
The problem seems to be related to that this plugin parses the HTML of the page content using the loadHTML() method of the DOMDocument class…
The problem with this parsing is that, it has some specific processing technique for the content between the <script> tags, as everything between the script tag will be handle as text. This doesn’t allow using other html tags between the <script></script> elements. In our case we need to add and remove elements with JavaScript: e.g.:
<script type=”text/javascript”>
…
$(‘<div class=”nsl-clear”></div>’).appendTo($form);
…
</script>
so we need to use HTML tags inside the script tags.
Another problem with this parsing is that, it has a html element auto closing feature and actually this is what causes the problem as it messes up the JavaScript code by closing it earlier than expected:
<script type=”text/javascript”>
…
$(‘<div class=”nsl-clear”></script></form></div>’).appendTo($form);
making the remaining JavaScript code after the closing </div> element just simple text:
So on our end I am sorry, but there is no possible solution for this problem. But in the code I can see you have options to exclude some pages from this “HTML optimization”.
So I would suggest excluding the /my-account page and the /checkout page and that will fix the problem. You could use a custom code like:
function exclude_pages_from_html_optimization($value, $data) {
if($data[‘post_id’] == ’60’ || $data[‘post_id’] == ’61’ ) { return false; }
return $value;
}
add_filter(‘is_optimization_allowed’, ‘exclude_pages_from_html_optimization’, 10, 2);
where 60 and 61 is the ID of your /my-account and /checkout pages. To find out the ID of the pages, you could go to WordPress > Pages, then open the “My account” and “Checkout” pages for edit.
If you inspect their URL it will look something like:
https://example.com/wp-admin/post.php?post=60&action=edit
where the “post” GET parameter contains the ID.
The custom PHP code I suggested above could be entered at the end of your functions.php file or you could create a custom Plugin and place these codes there.
If you are wondering if there is a more optimal solution, then I would suggest getting in touch with the developers of “PB SEO Friendly Images” as they know their codes better.