Problem with <script> (and closing html tags)

I believe I have found some bugs with <script>:

  1. The use of <script> placed out of <head></head> does not work automatically neither manually.
    Cases of use: scripts in the footer and JSON LD
    For other users: My current solution is to do not export the script and place the code manually in function.php after /* Pinegrow generated Enqueue Styles End */

  2. When using JSON LD, the convert removes the attribute ´type="application/ld+json"´ which will fail to its purpose and also will cause an error in the console - wherever the script is placed.

  3. Sometimes the closing tags </body> and </html> are removed from my html. I noticed more in index.html. Is there any reason for that?
    It makes my javascript to fail when testing the layout


Hey @sirojuntle,
Me again! Maybe somebody else will have some input.

For point 1 - a couple of points. How are you handling the scripts within Pinegrow. For adding the JSON-LD library, you need to make sure that you are enqueueing the script using the WP actions. This will put it into the functions.php automatically.

Here the library script is in my footer being delivered by CDN.
If you HAVE to put it in manually, it is recommended that you enqueue in the ‘inc/custom.php’ file. That way it doesn’t get overwritten at each export.

For point 2 - If you add the script directly to the page, export will place the script through the functions.php file using ‘wp_add_inline_script’. This doesn’t allow for directly adding a type. Instead you will have to either use a PHP method to add the script, like the PHP JSON-LD library, or potentially directly echo the script to the page in a PHP block (not sure if echo will handle JSON data correctly.
I also don’t think that a filter like script_loader_tag will work because I don’t think the inline script gets passed with a dynamic tag that can be changed through a filter.

For point 3 - The only times I have seen that happen is when the HTML in the document is malformed.

Just my $.02,

1 Like

Thank you again, @RobM,

The problem with enqueueing scripts in footer, even when manually adding the Enqueue, it wasn’t adding the script in the footer or it was having problem addin get_template_directory_uri() for relative path scripts. But I think I figured it ou with the help of your another answer.

In fact, my HTML was malformed. After I fixed that, it looks like the scripts in footer are working both automatically or manually.

And about JSONLD I think I will end using a SEO plugin for that, but it is nice to know we have a option!

Thank you!