• Hi Frank,

    I discovered that if title/description of videos contains quotation marks, it may break the generated itemprop html code. This might only occur in certain plugin combinations, most probably when some of them is trying to optimize HTML structure. I saw you already apply esc_attr to the retrieved youtube data so I assume that should be safe corresponding to the WordPress KB database.

    However, here is a quick workaround if someone else has a small number of videos not passing Google’s validation steps whilst the majority is working. Please add the following to your theme’s functions.php, which removes html-encoded quotes from all tags.

    
    /* remove encoded quotes at all */
    function afe_fix_lyte_quote_hanlding($tmpl, $type) {
            return str_replace('"', "", $tmpl );
    }
    
    add_filter('lyte_match_postparse_template', 'afe_fix_lyte_quote_hanlding', 10, 2);
    

    Cheers,

    Matthieu

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    thanks, very interesting Matthieu-P! What plugin are you using to optimize the HTML and does the problem go away when disabling said HTML optimization?

    Thread Starter Matthieu-P. Schapranow

    (@theschappy)

    Nope, I am aware of the enabled plugins autoptimize and W3 total cache, where I disabled at least the options to optimize HTML code but not the full plugins without any lick. As a result, I created the short code to remove all quotes. If you are looking for a youtube url to test, I stumbled across this video, which contains many special characters in the description and title attributes:

    Cheers,

    Matthieu

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    so HTML optimization is off in both W3TC and AO and still this occurs?

    Thread Starter Matthieu-P. Schapranow

    (@theschappy)

    Hi Frank,

    in the meantime, I was able to rule out both plugins AO and W3TC. Even if I disable them both, I need to add the workaround to my functions.php to sanitize the HTML output. Looks somehow weird for me.

    Best,

    Matthieu

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Cloudflare or similar services maybe?

    Thread Starter Matthieu-P. Schapranow

    (@theschappy)

    Hi Frank,

    No, all files are hosted at one server, no CDNs incorporated for that site. I also tried to disable mod_pagespeed temporarily, but no improvements. Interestingly the title tag used in the lyte-wrapper div works correctly although it also contains quotes. I noticed that it uses htmlentities instead of esc_attr, but using it in my workaround did not fix the issue.

    Cheers,

    Matthieu

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    taking a step back; does Google’s “structured data test tool” also complain about broken structured data when not removing "? Because purely from a HTML point of view having " in the itemprops does not break the attribute ?

    Thread Starter Matthieu-P. Schapranow

    (@theschappy)

    Well, that is actually the problem. The structured data test tool does not complain, but the description is not detected correct, instead it is only detected until the first appearance of a ". The W3C validator complain about the generated HTML and marks it as invalid, because it stops processing after the first occurrence of a " and everything else is misinterpreted as HTML tags. Finally, Google’s new search console complains about invalid structured data for all pages containing " in its description, this is how my attention was raised. Restarting the validation multiple times failed for these pages. After I added the snippet to the function.php the validation in Google’s search console succeeded.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    The W3C validator complain about the generated HTML and marks it as invalid, because it stops processing after the first occurrence of a " and everything else is misinterpreted as HTML tags.

    that’s pretty damning evidence. is there a spec (that you know of) that says values of itemprop attributes should not have html-entities (like ") in them?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Thread Starter Matthieu-P. Schapranow

    (@theschappy)

    Thanks Frank,

    I marked the issue as solved. I believe another plugin is “optimizing” somehow the generated HTML code resulting the weird behavior. For the time being, I can live with the quick fix mentioned above.

    Cheers,

    Matthieu

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Quotation marks in description/title may break HTML’ is closed to new replies.