['AEO: answer engines', 6], 'struct' => ['Site structure', 5], 'a11y' => ['Accessibility basics', 3], 'local' => ['Local SEO', 4], 'shop' => ['Online shop', 4]]; } function aiotsa_more_registry() { return [ 't_hreflang' => ['tech', 'hreflang tags', 1], 't_params' => ['tech', 'Addresses with parameters', 1], 't_sitemap_cov' => ['tech', 'Sitemap covers the site', 2], 'o_schema_req' => ['onpage', 'Schema has its main fields', 2], 'e_direct' => ['aeo', 'Direct answer under question headings', 2], 'e_format' => ['aeo', 'Lists and tables', 1], 'e_paras' => ['aeo', 'Short paragraphs', 1], 'e_schema' => ['aeo', 'FAQ, HowTo or Q&A schema', 0], 'e_speak' => ['aeo', 'Speakable schema', 0], 'g_fetch' => ['ai', 'AI crawlers can open the site', 0], 'g_llms' => ['ai', 'Links in llms.txt', 0], 'g_facts' => ['ai', 'Facts and figures', 1], 'g_alone' => ['ai', 'Paragraphs that stand alone', 1], 'g_entity' => ['ai', 'Publisher identity', 2], 'g_author' => ['ai', 'Author profile in the schema', 1], 'g_fresh' => ['ai', 'Updated date shown', 1], 's_source' => ['speed', 'Where the speed numbers come from', 0], 's_psi_opps' => ['speed', 'PageSpeed: what to improve', 0], 'u_depth' => ['struct', 'Clicks from the home page', 2], 'u_dup' => ['struct', 'Pages with the same text', 2], 'u_top' => ['struct', 'Most linked pages', 0], 'x_lang' => ['a11y', 'Page language', 1], 'x_linktext' => ['a11y', 'Link text', 1], 'x_emptylink' => ['a11y', 'Links without text', 1], 'x_labels' => ['a11y', 'Form labels', 1], 'l_schema' => ['local', 'LocalBusiness schema', 2], 'l_nap' => ['local', 'Name, address and phone', 2], 'l_hours' => ['local', 'Opening hours', 1], 'l_map' => ['local', 'Map', 1], 'p_schema' => ['shop', 'Product schema', 1], 'p_price' => ['shop', 'Price and availability', 2], 'p_rating' => ['shop', 'Ratings and reviews', 1], 'p_ids' => ['shop', 'Brand and product ID', 1], ]; } function aiotsa_more_has($v) { return $v !== null && !(is_string($v) && trim($v) === '') && !(is_array($v) && !$v) && $v !== false; } function aiotsa_more_list($v) { return (is_array($v) && array_keys($v) === range(0, count($v) - 1)) ? $v : ($v === null ? [] : [$v]); } function aiotsa_more_schema_req() { $a = ['headline', 'author', 'datePublished', 'image']; return ['Article' => $a, 'BlogPosting' => $a, 'NewsArticle' => $a, 'TechArticle' => ['headline', 'author', 'datePublished'], 'Product' => ['name', 'image', 'offers'], 'FAQPage' => ['mainEntity'], 'QAPage' => ['mainEntity'], 'HowTo' => ['name', 'step'], 'Recipe' => ['name', 'image', 'recipeIngredient'], 'Organization' => ['name', 'url'], 'LocalBusiness' => ['name', 'address', 'telephone'], 'Person' => ['name'], 'WebSite' => ['name', 'url'], 'BreadcrumbList' => ['itemListElement'], 'Event' => ['name', 'startDate', 'location'], 'VideoObject' => ['name', 'thumbnailUrl', 'uploadDate'], 'Review' => ['itemReviewed', 'author']]; } function aiotsa_more_is_local($ty) { return (bool) preg_match('/^(LocalBusiness|Restaurant|Store|Dentist|Physician|MedicalClinic|Hotel|LodgingBusiness|AutoRepair|BeautySalon|HairSalon|RealEstateAgent|LegalService|Attorney|Electrician|Plumber|FoodEstablishment|CafeOrCoffeeShop|Bakery|Pharmacy|ProfessionalService|HomeAndConstructionBusiness|FinancialService|TravelAgency|SportsActivityLocation|EducationalOrganization|School)$/', $ty); } /** Walk JSON-LD: which expected fields are missing, and a few facts the checks need. */ function aiotsa_more_schema($j, &$out, &$sf, $d = 0) { if ($d > 6 || !is_array($j)) return; if (isset($j['@type'])) { $req = aiotsa_more_schema_req(); $h = 'aiotsa_more_has'; foreach ((array) $j['@type'] as $ty) { if (!is_string($ty)) continue; $rq = $req[$ty] ?? (aiotsa_more_is_local($ty) ? $req['LocalBusiness'] : null); if ($rq && count($out) < 12) { $miss = []; foreach ($rq as $k) if (!$h($j[$k] ?? null) && !($k === 'offers' && ($h($j['review'] ?? null) || $h($j['aggregateRating'] ?? null)))) $miss[] = $k; $out[] = [$ty, $miss]; } if (preg_match('/Article|BlogPosting/', $ty)) { if ($h($j['dateModified'] ?? null)) $sf['mod'] = 1; $au = aiotsa_more_list($j['author'] ?? null)[0] ?? null; if (is_array($au) && ($h($au['url'] ?? null) || $h($au['sameAs'] ?? null))) $sf['aurl'] = 1; } if ($ty === 'Organization' || $ty === 'Person' || aiotsa_more_is_local($ty)) { $e = $sf['ent'] ?? [0, 0]; if ($h($j['name'] ?? null)) $e[0] = 1; $e[1] = max($e[1], count(aiotsa_more_list($j['sameAs'] ?? null))); $sf['ent'] = $e; } if (aiotsa_more_is_local($ty)) { $l = $sf['loc'] ?? []; $l['type'] = $ty; foreach (['address' => 'a', 'telephone' => 't', 'openingHoursSpecification' => 'h', 'openingHours' => 'h'] as $k => $s) if ($h($j[$k] ?? null)) $l[$s] = 1; $sf['loc'] = $l; } if ($ty === 'Product') { $p = $sf['prd'] ?? ['x' => 1]; $o = aiotsa_more_list($j['offers'] ?? null)[0] ?? null; if (is_array($o)) { if ($h($o['price'] ?? null) || $h($o['lowPrice'] ?? null)) $p['price'] = 1; if ($h($o['priceCurrency'] ?? null)) $p['cur'] = 1; if ($h($o['availability'] ?? null)) $p['avail'] = 1; } if ($h($j['aggregateRating'] ?? null) || $h($j['review'] ?? null)) $p['rating'] = 1; if ($h($j['brand'] ?? null)) $p['brand'] = 1; foreach (['sku', 'gtin', 'gtin8', 'gtin12', 'gtin13', 'gtin14', 'mpn'] as $k) if ($h($j[$k] ?? null)) $p['id'] = 1; $sf['prd'] = $p; } if (!empty($j['speakable'])) $sf['spk'] = 1; } } foreach ($j as $v) if (is_array($v)) aiotsa_more_schema($v, $out, $sf, $d + 1); } /** Extra facts of one page. Called from aiotsa_parse() while the document is still whole. Only what is found is kept, to keep the saved data small. */ function aiotsa_more_parse($x, $main, $html, $url, $f) { $m = []; $sob = []; $sf = []; foreach ($x->query('//script[@type="application/ld+json"]') as $s) { $j = json_decode($s->textContent, true); if (is_array($j)) aiotsa_more_schema($j, $sob, $sf); } $gaps = array_values(array_filter($sob, function ($o) { return !empty($o[1]); })); if ($gaps) $m['sob'] = array_slice($gaps, 0, 6); foreach (['aurl', 'spk', 'ent', 'loc', 'prd'] as $k) if (isset($sf[$k])) $m[$k] = $sf[$k]; if ($f['lang'] !== '') $m['lg'] = 1; $wc = 'aiotsa_wc'; $txt = ''; if ($main) { $qa = [0, 0]; foreach ($x->query('.//h2|.//h3|.//h4', $main) as $h) { $tx = trim(preg_replace('/\s+/u', ' ', $h->textContent)); if ($tx === '' || !(mb_substr($tx, -1) === '?' || preg_match('/^(how|what|why|when|where|which|who|can|does|do|is|are|should)\b/i', $tx))) continue; $qa[1]++; $nx = $h->nextSibling; while ($nx && !($nx instanceof DOMElement)) $nx = $nx->nextSibling; if (!$nx || preg_match('/^h[1-6]$/i', $nx->nodeName)) continue; $tg = strtolower($nx->nodeName); $node = $nx; if (!in_array($tg, ['p', 'ul', 'ol', 'table'], true)) { $in = $x->query('.//p|.//li', $nx); if ($in->length) $node = $in->item(0); } $aw = $wc($node->textContent); if ($aw >= 6 && $aw <= 100) $qa[0]++; } if ($qa[1]) $m['qa'] = $qa; $ls = 0; foreach ($x->query('.//ul|.//ol', $main) as $l) if ($x->query('./li', $l)->length >= 3) $ls++; foreach ($x->query('.//table', $main) as $t) if ($x->query('.//tr', $t)->length >= 2) $ls++; if ($ls) $m['ls'] = $ls; $pr = 0; $lp = 0; foreach ($x->query('.//p', $main) as $p) { $w = $wc($p->textContent); if ($w < 8) continue; $pr++; if ($w > 150) $lp++; } if ($pr) $m['pr'] = $pr; if ($lp) $m['lp'] = $lp; $txt = mb_substr(trim(preg_replace('/\s+/u', ' ', $main->textContent)), 0, 20000); $fc = preg_match_all('/(?:\d[\d.,]*\s?(?:%|percent|million|billion|crore|lakh|km|kg|mb|gb|ms|px|usd|inr|eur)|[$€£₹]\s?\d[\d.,]*|\b(?:19|20)\d{2}\b|\b\d{2,}[\d.,]*\b)/iu', $txt); if ($fc) $m['fc'] = min(99, (int) $fc); $vg = preg_match_all('/\b(as (mentioned|discussed|stated|noted|shown|explained) (above|earlier|before|previously)|see above|the above (section|example|table)|as we saw|in the previous section|mentioned earlier)\b/i', $txt); if ($vg) $m['vg'] = (int) $vg; } if (!empty($sf['mod']) || preg_match('/\b(last updated|updated on|last modified|updated:|reviewed on)\b/i', mb_substr($txt, 0, 3000) . ' ' . mb_substr($txt, -1500))) $m['up'] = 1; $bl = 0; $el = 0; foreach ($x->query('//a[@href]') as $a) { $h = trim($a->getAttribute('href')); if ($h === '' || preg_match('#^(javascript:|\#$)#i', $h)) continue; $lt = strtolower(trim(preg_replace('/\s+/u', ' ', $a->textContent))); if ($lt === '') { if (trim($a->getAttribute('aria-label')) === '' && trim($a->getAttribute('title')) === '' && trim($a->getAttribute('aria-labelledby')) === '' && !$x->query('.//img[normalize-space(@alt) != ""]|.//*[normalize-space(@aria-label) != ""]|.//svg/title', $a)->length) $el++; } elseif (preg_match('/^(click here|here|read more|more|learn more|this|link|click|continue|details|go)$/', $lt)) $bl++; } if ($bl) $m['bl'] = min(99, $bl); if ($el) $m['el'] = min(99, $el); $fl = 0; $nl = 0; foreach ($x->query('//input|//select|//textarea') as $in) { $ty = strtolower($in->getAttribute('type')); if (in_array($ty, ['hidden', 'submit', 'button', 'image', 'reset'], true)) continue; $fl++; $ok = trim($in->getAttribute('aria-label')) !== '' || trim($in->getAttribute('aria-labelledby')) !== '' || trim($in->getAttribute('title')) !== ''; if (!$ok && ($id = $in->getAttribute('id')) !== '' && strpos($id, '"') === false) $ok = $x->query('//label[@for="' . $id . '"]')->length > 0; if (!$ok) for ($p = $in->parentNode; $p; $p = $p->parentNode) if (strtolower($p->nodeName) === 'label') { $ok = true; break; } if (!$ok) $nl++; } if ($fl) $m['fl'] = min(99, $fl); if ($nl) $m['nl'] = min(99, $nl); if ($x->query('//a[starts-with(@href, "tel:")]')->length) $m['tel'] = 1; if (!empty($sf['loc']['a']) || $x->query('//address|//*[@itemprop="address"]')->length) $m['adr'] = 1; if (preg_match('#]+src=["\'][^"\']*(google\.[a-z.]+/maps|maps\.google\.|openstreetmap\.org|maps\.app\.goo\.gl)#i', $html)) $m['map'] = 1; $hl = []; foreach ($x->query('//link[@rel="alternate"][@hreflang]') as $l) if (count($hl) < 40) $hl[] = [strtolower($l->getAttribute('hreflang')), WP_Http::make_absolute_url($l->getAttribute('href'), $url)]; if ($hl) $m['hl'] = $hl; return $m; } function aiotsa_more_key($u) { $u = preg_replace('/#.*$/', '', strtolower(trim((string) $u))); $u = preg_replace('#^https?://(www\.)?#', '', $u); return untrailingslashit($u); } /** The results of the new checks. Called at the end of aiotsa_task_finalize(), before the score. */ function aiotsa_more_finalize(&$A, $items, $posts) { $R = &$A['results']; $C = &$A['summary']['ctx']; $own = $A['mode'] === 'own'; $single = $A['mode'] === 'page'; $n = count($items); $np = count($posts); $mx = function ($i) { return (array) ($i['data']['mx'] ?? []); }; $r = 'aiotsa_r'; $pl = function ($rows, $extra = null) use ($own) { return aiotsa_plist($rows, $own, $extra); }; $pick = function ($set, $fn) { return array_values(array_filter($set, $fn)); }; $share = function ($id, $rows, $total, $okAt, $okMsg, $badMsg, $fix, $lst = [], $failAt = null) use (&$R) { $a = count($rows); $R[$id] = $a / $total >= $okAt ? aiotsa_r('pass', $okMsg, [$a, $total]) : aiotsa_r($failAt !== null && $a / $total <= $failAt ? 'fail' : 'warn', $badMsg, [$a, $total], $fix, [], $lst); }; // Audits made before 1.2.0 have no extra facts: the new checks are left out rather than shown as failed. $fresh = $n && count($pick($items, function ($i) { return isset($i['data']['mx']); })) === $n; $H = (array) ($C['home']['mx'] ?? []); if ($np && $fresh) { $qp = $pick($posts, function ($i) use ($mx) { return ($mx($i)['qa'][1] ?? 0) > 0; }); $qt = 0; $qo = 0; foreach ($qp as $i) { $qt += $mx($i)['qa'][1]; $qo += $mx($i)['qa'][0]; } $R['e_direct'] = !$qt ? aiotsa_skip('No question headings found yet.') : ($qo / $qt >= 0.6 ? $r('pass', '%1$d of %2$d question headings are followed by a short, direct answer.', [$qo, $qt]) : $r($qo / $qt < 0.25 ? 'fail' : 'warn', 'Only %1$d of %2$d question headings are followed by a short, direct answer.', [$qo, $qt], 'Right under each question heading, answer in 2-3 sentences (about 40-60 words). Add the detail after that.', [], $pl($pick($qp, function ($i) use ($mx) { return $mx($i)['qa'][0] < $mx($i)['qa'][1]; }), function ($i) use ($mx) { return $mx($i)['qa'][0] . ' / ' . $mx($i)['qa'][1]; }))); $isq = function ($i) { return (bool) array_intersect((array) ($i['data']['sch'] ?? []), ['FAQPage', 'HowTo', 'QAPage']); }; $withText = $pick($posts, function ($i) { return !empty($i['data']['faq']); }); $withSch = $pick($posts, $isq); $gap = $pick($withText, function ($i) use ($isq) { return !$isq($i); }); $R['e_schema'] = !$withText && !$withSch ? $r('info', 'No post has FAQ, HowTo or Q&A schema. This is optional: Google no longer shows FAQ or HowTo rich results. A visible FAQ section still helps readers and may help AI assistants find the answer.') : ($gap ? $r('info', '%1$d posts have an FAQ section but no FAQ schema. This is optional: Google no longer shows FAQ or HowTo rich results.', [count($gap)], '', [], $pl($gap)) : $r('pass', '%d posts have FAQ, HowTo or Q&A schema.', [count($withSch)])); $hasLs = function ($i) use ($mx) { return ($mx($i)['ls'] ?? 0) > 0; }; $share('e_format', $pick($posts, $hasLs), $np, 0.5, '%1$d of %2$d posts use a list or a table.', 'Only %1$d of %2$d posts use a list or a table.', 'Put steps in a numbered list and comparisons in a table. Answer engines lift these directly.', $pl($pick($posts, function ($i) use ($hasLs) { return !$hasLs($i); }))); $lp = $pick($posts, function ($i) use ($mx) { $d = $mx($i); return ($d['lp'] ?? 0) > 0 && ($d['pr'] ?? 0) > 0 && $d['lp'] / $d['pr'] > 0.2; }); $R['e_paras'] = count($lp) / $np <= 0.15 ? $r('pass', 'Paragraphs are short enough to quote on most posts.') : $r('warn', '%1$d of %2$d posts have many paragraphs longer than 150 words.', [count($lp), $np], 'Break long paragraphs into 2-4 sentences each.', [], $pl($lp, function ($i) use ($mx) { return (string) $mx($i)['lp']; })); $sp = count($pick($posts, function ($i) use ($mx) { return !empty($mx($i)['spk']); })); $R['e_speak'] = $sp ? $r('info', 'Speakable schema found on %d posts.', [$sp]) : $r('info', 'No Speakable schema. It is optional and used only by some voice assistants.'); $hasFc = function ($i) use ($mx) { return ($mx($i)['fc'] ?? 0) >= 3; }; $share('g_facts', $pick($posts, $hasFc), $np, 0.5, '%1$d of %2$d posts contain numbers, dates or figures.', 'Only %1$d of %2$d posts contain numbers, dates or figures.', 'Add specific facts: numbers, dates, prices, measurements. AI answers quote specifics, not general statements.', $pl($pick($posts, function ($i) use ($hasFc) { return !$hasFc($i); }))); $vg = $pick($posts, function ($i) use ($mx) { return ($mx($i)['vg'] ?? 0) > 0; }); $R['g_alone'] = count($vg) / $np <= 0.15 ? $r('pass', 'Few posts lean on phrases like "as mentioned above".') : $r('warn', '%1$d of %2$d posts use phrases like "as mentioned above".', [count($vg), $np], 'Rewrite those sentences so each paragraph makes sense when it is quoted alone.', [], $pl($vg, function ($i) use ($mx) { return (string) $mx($i)['vg']; })); $arts = $pick($posts, function ($i) { foreach ((array) ($i['data']['sch'] ?? []) as $t) if (preg_match('/Article|BlogPosting/', $t)) return true; return false; }); $au = count($pick($arts, function ($i) use ($mx) { return !empty($mx($i)['aurl']); })); $R['g_author'] = !$arts ? aiotsa_skip('No Article schema found.') : ($au / count($arts) >= 0.8 ? $r('pass', 'The author in the schema links to a profile on %1$d of %2$d posts.', [$au, count($arts)]) : $r('warn', 'The author in the schema links to a profile on only %1$d of %2$d posts.', [$au, count($arts)], 'In your SEO plugin, give each author a profile page or social link, so the schema author has a "url" or "sameAs".')); $share('g_fresh', $pick($posts, function ($i) use ($mx) { return !empty($mx($i)['up']); }), $np, 0.6, 'An updated date is shown on %1$d of %2$d posts.', 'An updated date is shown on only %1$d of %2$d posts.', 'Show "Last updated" on posts and keep dateModified in the schema.'); } if (!$single && isset($C['home']['mx'])) { $ent = $H['ent'] ?? null; $R['g_entity'] = !$ent ? $r('warn', 'The home page has no Organization or Person schema, so AI services cannot be sure who publishes the site.', [], 'Add Organization (or Person) schema with name, logo and "sameAs" links to your social profiles.') : ($ent[0] && $ent[1] >= 2 ? $r('pass', 'Organization or Person schema with a name and %d profile links.', [$ent[1]]) : $r('warn', 'Organization or Person schema is there, but it has %d "sameAs" profile links.', [$ent[1]], 'Add "sameAs" links to at least two profiles (LinkedIn, X, Facebook, YouTube, Wikipedia).')); $hl = (array) ($H['hl'] ?? []); if (!$hl) $R['t_hreflang'] = aiotsa_skip('The site has no hreflang tags. They are only needed for sites in more than one language.'); else { $bad = []; $self = false; $xd = false; $hk = aiotsa_more_key($C['home_url'] ?? $A['target']); foreach ($hl as $h) { if (!preg_match('/^(x-default|[a-z]{2,3}(-[a-z0-9]{2,8})*)$/', $h[0])) $bad[] = $h[0]; if (aiotsa_more_key($h[1]) === $hk) $self = true; if ($h[0] === 'x-default') $xd = true; } $probs = []; if ($bad) $probs[] = 'wrong codes: ' . implode(', ', array_slice($bad, 0, 6)); if (!$self) $probs[] = 'no tag points to the page itself'; if (!$xd) $probs[] = 'no x-default'; $R['t_hreflang'] = $probs ? $r('warn', '%1$d hreflang tags on the home page, with problems: %2$s.', [count($hl), implode('; ', $probs)], 'Each language version needs a tag for every version, including itself, plus an x-default.') : $r('pass', '%d hreflang tags on the home page, including the page itself and x-default.', [count($hl)]); } } if ($n && $fresh) { $sg = $pick($items, function ($i) use ($mx) { return !empty($mx($i)['sob']); }); $anySch = (bool) $pick($items, function ($i) { return !empty($i['data']['sch']); }); $R['o_schema_req'] = !$anySch ? aiotsa_skip('No structured data found.') : ($sg ? $r(count($sg) / $n >= 0.5 ? 'fail' : 'warn', '%1$d of %2$d pages have schema with missing fields.', [count($sg), $n], 'Fill the missing fields in your SEO plugin. Search engines ignore schema that is incomplete.', [], $pl($sg, function ($i) use ($mx) { return implode('; ', array_map(function ($o) { return $o[0] . ': ' . implode(', ', (array) $o[1]); }, $mx($i)['sob'])); })) : $r('pass', 'The schema we checked has its main fields filled.')); $rows = $pick($items, function ($i) use ($mx) { return empty($mx($i)['lg']) && empty($i['data']['local']); }); $R['x_lang'] = $rows ? $r('warn', '%1$d of %2$d pages do not set a language on the tag.', [count($rows), $n], 'Set the site language so screen readers pronounce the text correctly.', [], $pl($rows)) : $r('pass', 'All %d pages set a language.', [$n]); $rows = $pick($items, function ($i) use ($mx) { return ($mx($i)['bl'] ?? 0) > 0; }); $tot = 0; foreach ($rows as $i) $tot += $mx($i)['bl']; $R['x_linktext'] = !$rows ? $r('pass', 'No "click here" or "read more" links found.') : $r(count($rows) / $n > 0.5 ? 'fail' : 'warn', '%1$d links on %2$d pages say only "click here", "read more" or similar.', [$tot, count($rows)], 'Make the link text say where the link goes.', [], $pl($rows, function ($i) use ($mx) { return (string) $mx($i)['bl']; })); $rows = $pick($items, function ($i) use ($mx) { return ($mx($i)['el'] ?? 0) > 0; }); $R['x_emptylink'] = !$rows ? $r('pass', 'Every link has text or a label.') : $r('warn', '%d pages have links with no text and no label (often icon links).', [count($rows)], 'Add an aria-label to icon links, or alt text to the image inside.', [], $pl($rows, function ($i) use ($mx) { return (string) $mx($i)['el']; })); $ff = $pick($items, function ($i) use ($mx) { return ($mx($i)['fl'] ?? 0) > 0; }); $rows = $pick($ff, function ($i) use ($mx) { return ($mx($i)['nl'] ?? 0) > 0; }); $R['x_labels'] = !$ff ? aiotsa_skip('No form fields found.') : ($rows ? $r('warn', '%1$d of %2$d pages with forms have fields without a label.', [count($rows), count($ff)], 'Give every form field a visible