Extension:RichResults
Release status: stable |
|
|---|---|
| Implementation | Data extraction |
| Description | Adds JSON-LD structured data to article head for Google rich results. |
| Author(s) | Encyc team, Enki (Flounder ceotalk) |
| Latest version | 1.0.4 (2025-12-12) |
| MediaWiki | 1.43+ |
| PHP | 8.3+ |
| Licence | MIT License |
| Download | GitHub:
Note: |
| Example | Encyc.org |
| Translate the RichResults extension if it is available at translatewiki.net | |
The RichResults extension generates a JSON-LD script with structured data in the head of every article page. This can be used by search engines to make snippets.
This extension generates two data types:
- Organization - same throughout the site
- Article - dynamic, article-specific information
Background
[edit]Schema.org was created in 2011 by a joint effort from major search engines: Google, Bing, Yahoo!, and Yandex. The goal is to create a standard for webmasters to describe content to search engines. Practically, this has taken the form of a JSON-LD script in the HTML head. Its role in SEO is unclear, but it can help machines better understand the content.
Installation
[edit]- Download from GitHub and place in your extensions directory.
- Add the following code to your LocalSettings.php file:
wfLoadExtension( 'RichResults' );
- Run maintenance/run.php update
- Navigate to Special:Version to confirm.
Configuration parameters
[edit]Configurable by editing the Hooks.php file (src/Hooks.php).
Testing
[edit]- Use "View page source" to verify that the data is present in the head section.
- Test your site on the Google Rich Results Tester and the Schema.org Validator.
Alternate method using LocalSettings.php
[edit]Without installing the extension, the following code works fine in LocalSettings.php. It was tested on Encyc. It includes only the organization info.
# PHP header modification for Google Rich Results
# Minimal site-wide JSON-LD
$wgHooks['BeforePageDisplay'][] = function ( $out ) {
$out->addHeadItem( 'org-schema', '<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"@id": "https://Your URL/#organization",
"name": "Your Wiki Site Name",
"alternateName": "Your Alternate Name",
"url": "https://Your URL",
"sameAs": [
"https://x.com/X Name",
"https://reddit.com/r/Subreddit name"
],
"logo": "url of site logo",
"description": "Site description",
"address": {
"@type": "PostalAddress",
"addressRegion": "Two letter state abbreviation, e.g. NY",
"addressCountry": "US" //change if needed
}
}
</script>' );
};
