A console snippet to check if your page answers first (for AI search)
AI search engines like ChatGPT, Perplexity and Google's AI Overviews don't cite whole pages: they pull out passages that answer a question and cite their source. A practical way to make those passages easy to take is to
AI search engines like ChatGPT, Perplexity and Google's AI Overviews don't cite whole pages: they pull out passages that answer a question and cite their source. A practical way to make those passages easy to take is to put the answer in the first lines of the page and in the first lines under every heading.
Checking that by eye on a long page is slow. Here is a small snippet you can paste in the browser console: it lists every H1–H3 and the first 60 words that follow it, so you can see at a glance which sections answer and which ones warm up.
The snippet
// Paste in the browser console on any page.
// Prints each heading with the first 60 words that follow it.
(() => {
const words = (t) => t.replace(/\s+/g, ' ').trim().split(' ').filter(Boolean);
const heads = [...document.querySelectorAll('h1, h2, h3')];
const rows = heads.map((h) => {
let text = '';
let el = h.nextElementSibling;
while (el && !/^H[1-3]$/.test(el.tagName) && words(text).length < 60) {
text += ' ' + el.innerText;
el = el.nextElementSibling;
}
const w = words(text);
return {
level: h.tagName,
heading: h.innerText.trim().slice(0, 80),
first60: w.slice(0, 60).join(' '),
words: w.length,
};
});
console.table(rows);
return rows.length + ' headings checked';
})();
It only reads siblings that follow each heading, so it works best on pages where headings and paragraphs sit at the same level (most blog and CMS templates). If your theme wraps every section in its own <div>, adapt the loop.
How to read the table
For each row, ask three questions:
- Does the heading use the words of the question? "How much does a dental implant cost in Denver?" beats "Let's talk money".
- Do the first sentences give the answer? A number, a yes or no, a choice. Not "there are many factors to consider".
- Does the passage make sense on its own? A common guideline is that the first 40–60 words under a heading should answer it. That's a recommended practice, not a published engine rule, but it is the shape of a quotable passage.
Rows with words: 0 are headings with nothing under them before the next heading: worth a look too.
Fixing a section
The formula is two or three sentences, then the rest:
- name the topic with the words of the question;
- give the answer;
- then explain conditions, exceptions and examples.
Before: "In the ever-evolving landscape of the dental industry, there are many factors to consider."
After: "A dental implant in Denver usually costs between [low] and [high]. The price depends on three things."
(Prices left blank on purpose: it's an illustration.)
Try it
Run the snippet on one page tied to a question where AI answers don't cite you. Rewrite the first hundred words and three sections, then re-run it.
The method is lesson 5.1 of our free AEO and GEO course: The answer in the first lines.
I'm Adrian, founder of CiteProof.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.