I am facing a serious problem with HTML Tidy (latest version -- https://html-tidy.org).
In short: HTML tidy convert these lines of HTML codes
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<div class="wrap">
<span property="itemListElement" typeof="ListItem">
<a property="item" typeof="WebPage" title="Codes Category" href="https://mysite.works/codes/" class="taxonomy category">
<span property="name">Codes</span>
</a>
<meta property="position" content="1">
</span>
</div>
Into these lines of code -- Please take a close look at META TAGS placement.
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<div class="wrap">
<span property="itemListElement" typeof="ListItem">
<a property="item" typeof="WebPage" title="Codes Category" href="https://mysite.works/codes/" class="taxonomy category">
<span property="name">Codes</span>
</a>
</span>
<meta property="position" content="1">
</div>
This is causing some serious issues with schema validations. You can check the codes here: https://search.google.com/structured-data/testing-tool/u/0/
Because of this issue, the client's (URL: https://techswami.in ) breadcrumb navigation is not visible in search results.
What am I beautifying?
My client wanted me to make his/her website's source code look "clean, readable and tidy".
So I am using these lines of codes to make it work for him/her.
Note: this code works 100% perfectly on the following WordPress setup.
Code:
if( !is_user_logged_in() || !is_admin() ) {
function callback($buffer) {
$tidy = new Tidy();
$options = array('indent' => true, 'markup' => true, 'indent-spaces' => 2, 'tab-size' => 8, 'wrap' => 180, 'wrap-sections' => true, 'output-html' => true, 'hide-comments' => true, 'tidy-mark' => false);
$tidy->parseString("$buffer", $options);
$tidy->cleanRepair();
$buffer = $tidy;
return $buffer;
}
function buffer_start() { ob_start("callback"); }
function buffer_end() { if (ob_get_length()) ob_end_flush(); }
add_action('wp_loaded', 'buffer_start');
add_action('shutdown', 'buffer_end');
}
What help do I need from you guys?
Can you please tell me how do I prevent HTML Tidy from messing the META TAGS. I need the parameters.
Thanks.
The <meta>
tag should only be used in the parents elements: <head>
, <meta charset>
, <meta http-equiv>
Additionally, there is no property
attribute in the <meta>
element.
These are most likely the reasons that HTML-Tidy is cleaning the markup.
Sources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With