This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section
Microdata is a way of adding contextual information to your website and its contents, allowing search engines to better understand the information you provide them with.
Contextual information allows search engines to understand the meaning of the information presented on your website, which allows it to better answer more verbose 'natural language' queries where an understanding of the meaning helps to interpret the most relevant content to be displayed.
Microdata can be used to explain just about anything you would ever want to explain, and there are more 'schemas' being added on a regular basis. There are several vocabularies in existence, however at present the system favoured by search engines is that of schema.org.
To understand how search engines use the Microdata information take a look at this short video.
Microdata can be added to Joomla! using template overrides or with the use of plugins which allow you to insert microdata into specific resources.
As of Joomla! 3.2 there is a library within Joomla! which allows developers to pull in microdata without needing to format it correctly. The following resources are available by the author of the microdata library introducing the library and how to use it:
JMicrodata (since version 3.2) is a library to implement http://schema.org microdata semantics.
The JMicrodata class uses the types.json file which contains all available http://schema.org Types and Properties.
The types.json was automatically created with the https://github.com/PAlexcom/Spider4Schema web crawler.
For some usage examples you can see the library test file https://github.com/joomla/joomla-cms/blob/master/tests/unit/suites/libraries/joomla/microdata/JMicrodataTest.php
For a more detailed documentation of the library see the gist created by the author:
All Microdata HTML output is handled by the JMicrodata class.
the HTML Scope of the given Type, must be inside a HTML tag element.
the HTML of the given Property, must be inside a HTML tag element.
JMicrodata::htmlSpan($content, $property = '', $scope = '', $inverse = false);
<span itemscope itemtype="http://schema.org/$scope itemprop="$property"> $content </span>
the microdata in a tag, there is also available a JMicrodata::htmlDiv() method with the same functionalities.
JMicrodata::htmlMeta($content, $property, $scope = '', $inverse = false);
<meta $property $scope content='$content'>
the microdata in a <meta> tag with content for machines.
$microdata = JMicrodata($type = '', $flag = true);
Create a new instance of the JMicrodata class and setup the current Type, the flag param is for enabling or disabling HTML microdata semantics output. Fallback to Thing Type if the Type isn't available or given.
$microdata->enable($flag = true);
Enable or Disable HTML Microdata semantics output.
Return true if Microdata semantics HTML output are enabled.
Set a new Schema.org Type, there is also a $microdata->getType() function to retrieve the current Type.
Setup the Property if available in the current Type Scope, there is also a $microdata->getProperty() function to retrieve the current Property.
$microdata->content($value, $machineValue = null);
Setup a Text value or Content value for the Microdata, there is also a $microdata->getContent() function to retrieve the current Text value.
Setup a Fallback Type and Property, there are also the $microdata->getFallbackType() and $microdata->getFallbackProperty() to retrieve the Fallback Type and Fallback Property. Fallback to Thing Type if the Type isn't available, Fallback to null the Property if isn't available.
First of all you need to make an instance of the library in your extensions:
$microdata = new JMicrodata('Article');
So let's suppose that we have the following string which is part of your article and the current scope is Article:
echo 'Written by Alexandru Pruteanu';
And the microdata you need to add is an author property:
echo 'Written by' . $microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();
The library will display:
Written by <span itemprop='author' itemscope itemtype='https://schema.org/Person'> <span itemprop='name'> Alexandru Pruteanu </span> </span>
What happens if the current scope is something else than Article, for example a Product scope, and the current scope doesn't have an author property?
Well it will fallback in:
Written by <span itemscope itemtype='https://schema.org/Person'> <span itemprop='name'> Alexandru Pruteanu </span> </span>
If I want to disable the microdata semantics output?
You can simply disable the microdata output by calling the following function:
The library will display the following:
Written by Alexandru Pruteanu