English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Microdata  >  Build Open Graph

do_action( 'vikappointments_build_open_graph', mixed $dummy, JDocument $doc, VAPViewContents $handler )

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 WordPress configuration.

Parameters

$dummy

(mixed)  Internal environment argument. Always ignore it.

$doc

(JDocument)  The document instance able to manipulate the head of the page.

$handler

(VAPViewContents)  The handler instance used to manipulate the page contents.


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  mixed            $dummy    Internal environment argument (ignore it).
 * @param  JDocument        $doc      The document instance.
 * @param  VAPViewContents  $handler  The page content handler.
 */
add_action('vikappointments_build_open_graph', function($dummy, $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);
}, 10, 3);

Changelog

Version Description
1.0 Introduced.
Last Update: 2021-07-29
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information