Structured data and link previews
Structured data describe a page to the search engine in a machine-readable way: who wrote the article and when, where the breadcrumb navigation is, when the café is open. Open Graph tags, in turn, determine what the link preview looks like on social networks and in chat apps.
What structured data are
Structured data are a description of the content of a page in the schema.org vocabulary, which Google, Bing, Seznam and other services understand. The type (Article, Product, Event, LocalBusiness…) and the properties (headline, author, address…) are most often written in the JSON-LD format – a JSON block in a script element that is in no way tied to the HTML of the page. Google recommends it because it is the easiest to maintain. Other formats (microdata and RDFa as attributes in HTML) work too.
A search engine does not rank a page higher for structured data. They can, however, earn the page a rich result – rating stars, the price of a product, the date of an event, breadcrumb navigation instead of the address – and they help the search engine understand what the page is about. Nobody is guaranteed a rich result.
Which types Google uses in the results changes. For example, it showed rich results with frequently asked questions (FAQ) only for government and health websites from 2023 and removed them completely in 2026; it removed how-to results (HowTo) in 2023. The current overview is in the structured data gallery in the Google Search Central documentation. You do not need any special structured data or files to appear in AI Overviews (as of October 2026).
The main rule: structured data must describe what the visitor actually sees on the page. A rating that is not on the page or hidden text lead to a manual action and the loss of rich results.
An article: Article and BlogPosting
For articles, Google does not require any property; it recommends the headline, images, the author and the dates of publication and modification. Dates belong in the ISO 8601 format with a time zone – without it, Google assumes the time zone of the robot. In PHP, the json_encode() function converts an array with the data to JSON:
<?php
date_default_timezone_set('Europe/Prague');
$article = array(
'title' => 'Autumn coffee tasting',
'address' => 'https://www.example.com/events/autumn-tasting/',
'images' => array('https://www.example.com/photos/tasting-16x9.jpg', 'https://www.example.com/photos/tasting-4x3.jpg'),
'published' => 1791442800,
'modified' => 1791549000,
'author' => 'Jane Linden',
);
$data = array(
'@context' => 'https://schema.org',
'@type' => 'BlogPosting',
'headline' => $article['title'],
'image' => $article['images'],
'datePublished' => date('c', $article['published']),
'dateModified' => date('c', $article['modified']),
'author' => array(array('@type' => 'Person', 'name' => $article['author'], 'url' => 'https://www.example.com/about-us/')),
'mainEntityOfPage' => $article['address'],
);
echo '<script type="application/ld+json">'."\n"
.json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG)
."\n</script>\n";
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "Autumn coffee tasting",
"image": [
"https://www.example.com/photos/tasting-16x9.jpg",
"https://www.example.com/photos/tasting-4x3.jpg"
],
"datePublished": "2026-10-08T09:00:00+02:00",
"dateModified": "2026-10-09T14:30:00+02:00",
"author": [
{
"@type": "Person",
"name": "Jane Linden",
"url": "https://www.example.com/about-us/"
}
],
"mainEntityOfPage": "https://www.example.com/events/autumn-tasting/"
}
</script>
- The author is of the type Person (or Organization); name contains only the name without titles and job title. The url link should lead to a page about the author. Several authors = several items of the array.
- Images – Google recommends several high-resolution images (at least 50,000 pixels, that is width times height) in the aspect ratios 16:9, 4:3 and 1:1. Not a logo.
- The type – Article in general, BlogPosting for a blog, NewsArticle for news.
Watch out for </script> in the data
The JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_SLASHES flags make the JSON more readable (accented letters and slashes unchanged). The second one, however, turns off a protection that the default json_encode() gives for free: the slash in </script> is no longer converted to <\/script>. When the text </script> then gets into the title of an article or a comment, it ends the JSON-LD block and the browser runs the rest of the text as HTML – that is XSS (see XSS and safe output). The JSON_HEX_TAG flag converts the < and > characters to the notation \u003C and \u003E, which JSON reads the same way:
<?php
$data = array('headline' => 'Café </script> and tea');
echo json_encode($data), "\n";
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG), "\n";
{"headline":"Caf\u00e9 <\/script> and tea"}
{"headline":"Café </script> and tea"}
{"headline":"Café \u003C/script\u003E and tea"}
The first line is safe but less readable, the second is dangerous, the third is safe and readable. Do not use the htmlspecialchars() function on JSON in a script element – the content of a script is not decoded and the search engine would read the entities.
Breadcrumb navigation: BreadcrumbList
Breadcrumb navigation shows where the page sits in the structure of the website. Google may show it in the search result instead of the address. The items have an order (position from 1), a name and an address – for the last item (the current page) the address is optional:
<?php
$crumbs = array(
array('Home', 'https://www.example.com/'),
array('Events', 'https://www.example.com/events/'),
array('Autumn coffee tasting', 'https://www.example.com/events/autumn-tasting/'),
);
$items = array();
foreach($crumbs as $i => $d)
$items[] = array('@type' => 'ListItem', 'position' => $i + 1, 'name' => $d[0], 'item' => $d[1]);
$data = array('@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $items);
echo '<script type="application/ld+json">'.json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG).'</script>'."\n";
<script type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.example.com/"},{"@type":"ListItem","position":2,"name":"Events","item":"https://www.example.com/events/"},{"@type":"ListItem","position":3,"name":"Autumn coffee tasting","item":"https://www.example.com/events/autumn-tasting/"}]}</script>
A business or premises: LocalBusiness
For a business with premises, LocalBusiness or one of its more specific subtypes is suitable – CafeOrCoffeeShop for a café, further for example Restaurant, Store, Dentist. The data do not change, so they can be written directly into the template of the home page or the contact page:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "CafeOrCoffeeShop",
"name": "Linden Café",
"url": "https://www.example.com/",
"image": "https://www.example.com/photos/cafe.jpg",
"telephone": "+420 123 456 789",
"address": {
"@type": "PostalAddress",
"streetAddress": "Masarykova 12",
"addressLocality": "Brno",
"postalCode": "602 00",
"addressCountry": "CZ"
},
"openingHoursSpecification": [{
"@type": "OpeningHoursSpecification",
"dayOfWeek": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
"opens": "08:00",
"closes": "20:00"
}]
}
</script>
For premises, Google requires name and address and recommends the other properties. For a business without premises, the type is Organization with the properties name, url, logo and sameAs (an array of links to the profiles of the business on social networks). Keep the opening hours and the address the same as in the text of the page and in the profile of the business on maps.
Checking structured data
- Rich Results Test (search.google.com/test/rich-results) – which rich results Google can create from the page and which properties are missing. It can test an address as well as pasted code.
- Schema Markup Validator (validator.schema.org) – a check against the whole schema.org vocabulary, regardless of what Google uses.
- Search Console – reports by the types of structured data with errors across the whole website.
A link preview: Open Graph
When someone pastes a link into Facebook, LinkedIn, WhatsApp, Messenger or Slack, the service downloads the page and builds a preview with an image, a title and a description from its tags. The tags are defined by the Open Graph protocol (ogp.me) and are written with the property attribute, not name:
<?php
$page = array(
'title' => 'Autumn coffee tasting',
'description' => 'Taste five specialty coffees from Ethiopia, Kenya and Colombia with the roaster who selects them for the café.',
'address' => 'https://www.example.com/events/autumn-tasting/',
'image' => 'https://www.example.com/photos/tasting-1200x630.jpg',
'image_alt' => 'Cups of coffee on a tasting table',
);
$h = function($text){ return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); };
?>
<meta property="og:type" content="article">
<meta property="og:title" content="<?= $h($page['title']) ?>">
<meta property="og:description" content="<?= $h($page['description']) ?>">
<meta property="og:url" content="<?= $h($page['address']) ?>">
<meta property="og:image" content="<?= $h($page['image']) ?>">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="<?= $h($page['image_alt']) ?>">
<meta property="og:site_name" content="Linden Café">
<meta property="og:locale" content="en_US">
<meta name="twitter:card" content="summary_large_image">
- og:title, og:type, og:image and og:url are required by the protocol, the description is recommended. The title and description may differ from the title and the meta description for the search engine – shorter and more inviting to click.
- The image – Facebook recommends at least 1200 × 630 pixels (an aspect ratio of about 1.91:1), the smallest large preview is 600 × 315 and the file may be at most 8 MB. A full address with the protocol. The dimensions in og:image:width and og:image:height allow the image to be shown right at the first share; otherwise the service processes it only afterwards.
- twitter:card – the X network reads its own tags and when they are missing, it uses the Open Graph tags. It is therefore enough to add only the type of card: summary_large_image = a large image, summary = a small square next to the text.
- Dynamic content – preview services do not run JavaScript, the tags must be in the HTML straight from the server.
The services store the preview. After changing the image or the title, therefore force a reload in the debugging tool – Facebook has the Sharing Debugger (developers.facebook.com/tools/debug), LinkedIn the Post Inspector (linkedin.com/post-inspector). Facebook remembers the image by its address, so upload a new image under a new file name.
Related articles:
XSS and safe output
How search engines crawl and index a website
Sitemaps and multilingual sites (hreflang)
What a REST API is and how to return JSON in PHP