Before Add Microdata
do_action_ref_array( 'vikappointments_before_add_microdata', mixed $dummy, object &$json, bool $include, VAPViewContents $handler )
Fires while including the microdata within the head
of the document.
Description
Microdata is used to nest metadata within existing content on web pages. Search engines and web crawlers can extract and process microdata from a web page and use it to provide a richer browsing experience for users. Google and other major search engines support the Schema.org vocabulary for structured data.
This hook can be used to allow the plugins to manipulate the JSON object that will be used by search engines.
Parameters
- $dummy
-
(mixed) Internal environment argument. Always ignore it.
- &$json
-
(object) The JSON object including the microdata. An empty object by default.
- &$include
-
(bool) Whether to include the microdata or not.
- $handler
-
(VAPViewContents) The handler instance used to manipulate the page contents.
Example
The example below explains how to always force the microdata to include the phone number of an employee, even if it should be hidden.
/**
* Trigger event to allow the plugins to manipulate the JSON object
* that will be used by search engines.
*
* @param mixed $dummy Internal environment argument (ignore it).
* @param object &$json The JSON object.
* @param boolean &$include True whether the JSON object should be included into the document.
* @param VAPViewContents $handler The page content handler.
*/
add_action('vikappointments_before_add_microdata', function($dummy, &$json, &$include, $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;
}
// turn flag OFF if you wish to exlude microdata
// $include = false;
// get employee object
$employee = $page->employee;
if (!isset($json->telephone))
{
$json->telephone = $employee->get('phone');
}
}, 10, 4);
Changelog
Version | Description |
---|---|
1.0 | Introduced. |