Removing Quotation from MaxWords
It has to do with validation at https://validator.schema.org/
If any of the content in the schema contains quotation marks, it fails to pass validation. When I remove the quotation marks from the content, it passes without any issues. I also needed all other HTML tags to be stripped out and I already use the maxWords script posted here in the forums to truncate content on all of the websites I build, so I just figured using it here would work just as well. It works great (stripping out all of the html tags) but now I think I need it to remove the quotation marks if I am going to use it for the purpose of building JSON schemas.
I also think the issue is with rounded opening/closing double quotes, but not straight double quotes. I think this happens when the content is cut and pasted from a word processor into the WYSIWYG instead of typing it there.
The validation error is always JSON-LD Missing ',' or '}' in object declaration.
I have two pages that are exactly the same except one doesn't have the quotation marks. It passes validation. The one with quotation marks in the content fails validation.
It can be difficult to diagnose this without seeing the content itself, but here is some info I found on escaping JSON strings - something here may help:
If it is an issue with the "fancy" quotation marks, you may need to explicitly remove or escape the characters that are causing issues, since something like this:
str_replace('"', "", $string);
Will only remove standard double quotes, so you'd need to add an extra str_replace() step for each additional character you want to remove. (It's also possible to use arrays to remove multiple characters with a single str_replace() call, examples in the PHP docs: https://www.php.net/manual/en/function.str-replace.php)
Let me know if you have any other questions!