Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  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.
Ultimo aggiornamento: 2021-07-29
Utile?
Potrebbe interessarti:

Questo sito web utilizza i cookie

Questo sito web utilizza cookie e tecnologie simili. Alcune di queste tecnologie sono necessarie per il corretto funzionamento del sito web (essenziali). Altre tecnologie sono utilizzate per valutare il comportamento degli utenti (analisi), per integrare media esterni o per scopi pubblicitari. Se l'utente accetta, queste tecnologie vengono attivate. I dettagli sono riportati nella Privacy Policy. Da questa stessa pagina è inoltre possibile aggiornare/revocare il consenso. Se non si fornisce il consenso, verranno attivati solo i cookie con funzioni essenziali.

Sul nostro sito web utilizziamo tecnologie provenienti dagli Stati Uniti. Pertanto, se acconsentite, acconsentite anche al trasferimento dei vostri dati negli Stati Uniti. Desideriamo sottolineare che gli Stati Uniti non hanno un livello di protezione dei dati paragonabile a quello dell'Unione Europea e che qualsiasi azienda statunitense può essere obbligata dalle autorità statali a consegnare i vostri dati senza che voi abbiate alcuno strumento efficace di protezione legale contro questo.