Build Open Graph
public function onBuildOpenGraph(JDocument $doc, VAPViewContents $handler) : void
Fires while including the OpenGraph directives within the head
of the document.
Description
The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.
This hook can be used to allow the plugins to include specific meta data to extend the Open Graph schema.
TIP: it is possible to add/alter meta data by using the following code:
$doc->setMetaData('og:title', 'This is my OG title');
Here's a list of meta data automatically generated by the plugin.
og:locale
- the default language of the website.og:locale:alternate
- an additional supported language. Repeats for each supported language.og:site_name
- the name of the website, taken from the Joomla configuration.
Parameters
- $doc
-
(JDocument) The document instance able to manipulate the head of the page.
- $handler
-
(VAPViewContents) The handler instance used to manipulate the page contents.
Return Value
None.
Example
The example below includes the gender of the employee, assuming that such information is specified through an apposite custom field.
/**
* Trigger hook to allow the plugins to add meta data according to
* OPEN GRAPH protocol.
*
* @param JDocument $doc The document instance.
* @param VAPViewContents $handler The page content handler.
*/
public function onBuildOpenGraph($doc, $handler)
{
// get current plugin page
$page = $handler->page;
// make sure we are within the details page of an employee
if (!preg_match("/^VikAppointmentsViewemployeesearch$/i", get_class($page)))
{
// do not go ahead.
return;
}
// get employee object
$employee = $page->employee;
// fetch gender from custom field (first option 'Male', second option 'Female')
$gender = $employee->field_gender == 0 ? 'male' : 'female';
// register gender as metadata
$doc->setMetaData('profile:gender', $gender);
}
Changelog
Version | Description |
---|---|
1.7 | Introduced. |