Inline script breaks XML Sitemap (2)
-
To follow up on the previous issue reported here. I would like to share a suggestion.
To recap, I use Yoast SEO. The XML sitemap /page-sitemap.xml has extra jQuery added at the top of the xml file, which breaks the page. Google Search Console reports:
Unsupported file format – Your Sitemap does not appear to be in a supported format. Please ensure that it meets our Sitemap guidelines and resubmit.
When I turn off your plugin, the issue is fixed.The sitemap xml file looks like this:
<script> jQuery(document).ready(function(){ jQuery("#mwtxmtlv.rotate-text").textrotator({ animation: "spin", separator: "|", speed: 10000 }); }); </script> <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//www.ergo3.co.uk/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?> <urlset xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:image="https://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9 https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd https://www.google.com/schemas/sitemap-image/1.1 https://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
I have discovered that the shortcode ‘saeidrotate’ is instructed to ‘echo’ an inline js script. This is wrong practice as it breaks the WordPress loops. Instead of using ‘echo’, I recommend returning the script as part of the shortcode function.
So instead of:
echo $rotatejquery;
use
return $rotatejquery.'<span id="'.$id.'" class="'.$class.'">'.do_shortcode($content).'</span>';
This has fixed the problem.
Author, it would be a good idea to implement this in your code if this solution is approved.
- The topic ‘Inline script breaks XML Sitemap (2)’ is closed to new replies.