I'm while using Sourcerer plugin to make use of PHP code within my articles. I must make use of the Joomla API/framework within my article to dynamically set the HTML meta data along with other stuff. I found the setHeadData method which should allow me do this however i have simply no clue regarding how calling it.

[Q] Can someone produce 1 example or point me to some tutorial that will assist me to get began on by using their joomla API/framework please?

Answer

In line with the numerous feedbacks all pointing within the same direction, utilizing a content wordpress plugin to change the mind information is correctly much better than carrying this out with an article. If much like me for you to do this within an article here's what Used to do:

(1) I made use of the snippet supplied by ezpresso to create the mind data within my article.
(2) I modified the libraries/joomla/document/html/renderer/mind.php file to alter how a mind data was set there.

For example you are able to set the title meta tag at step (1) after which at step (2) replace the next line:

$strHtml .= $tab.'<title>'.htmlspecialchars($document->getTitle()).'</title>'.$lnEnd;

with that one:

$strHtml .= $tab.'<title>'.htmlspecialchars($document['metaTags']['standard']['title']).'</title>'.$lnEnd;

You could also wish to consider libraries/joomla/document/html/renderer/mind.php to complete more cleanup within the mind, like eliminating the generator meta tag that Joomla card inserts.

This is actually the source code from the method you're mentioning to:

/**
 * Set the html document head data
 *
 * @access  public
 * @param   array   $data   The document head data in array form
 */
function setHeadData($data)
{
    $this->title        = (isset($data['title'])) ? $data['title'] : $this->title;
    $this->description  = (isset($data['description'])) ? $data['description'] : $this->description;
    $this->link         = (isset($data['link'])) ? $data['link'] : $this->link;
    $this->_metaTags    = (isset($data['metaTags'])) ? $data['metaTags'] : $this->_metaTags;
    $this->_links       = (isset($data['links'])) ? $data['links'] : $this->_links;
    $this->_styleSheets = (isset($data['styleSheets'])) ? $data['styleSheets'] : $this->_styleSheets;
    $this->_style       = (isset($data['style'])) ? $data['style'] : $this->_style;
    $this->_scripts     = (isset($data['scripts'])) ? $data['scripts'] : $this->_scripts;
    $this->_script      = (isset($data['script'])) ? $data['script'] : $this->_script;
    $this->_custom      = (isset($data['custom'])) ? $data['custom'] : $this->_custom;
}

It's implemented inside a JDocumentHtml class, that is situated inside a libraries/joomla/document/html/html.php directory.

Below may be the links to a few of the good examples of using it:

I suppose you might call the setHeadData method such as this:

$doc =& JFactory::getDocument();
$options = $doc->getHeadData();
$options['metaTags'] = array("tag1", "tag2", "tag3"); // you may change the meta tags here
$doc->setHeadData($options); 

Putting PHP within the article isn't an excellent way to complete what you're attempting to do. Joomla frameworks comes with an order of operation that determines when various functions and plug ins run. Because of an order of operation, you will find numerous functions which will happen after articles is made, most likely killing any changes you are making from inside the content. You'd be best either utilizing an extension to deal with game titles and meta data instead of trying to get it done within the article.