Back to Document class

Method setMetaData

public \Joomla\CMS\Document\Document
setMetaData
(mixed $name, mixed $content, mixed $attribute = 'name')
Sets or alters a meta tag.
Parameters
  • string $name Name of the meta HTML tag
  • mixed $content Value of the meta HTML tag as array or string
  • string $attribute Attribute to use in the meta HTML tag
Returns
  • \Joomla\CMS\Document\Document instance of $this to allow chaining
Since
  • 1.7.0
Class: Document
Project: Joomla

Method setMetaData - Source code

/**
 * Sets or alters a meta tag.
 *
 * @param   string  $name       Name of the meta HTML tag
 * @param   mixed   $content    Value of the meta HTML tag as array or string
 * @param   string  $attribute  Attribute to use in the meta HTML tag
 *
 * @return  Document instance of $this to allow chaining
 *
 * @since   1.7.0
 */
public function setMetaData($name, $content, $attribute = 'name')
{
    // Pop the element off the end of array if target function expects a string or this http_equiv parameter.
    if (\is_array($content) && (\in_array($name, array('generator', 'description')) || !\is_string($attribute))) {
        $content = array_pop($content);
    }
    // B/C old http_equiv parameter.
    if (!\is_string($attribute)) {
        $attribute = $attribute == true ? 'http-equiv' : 'name';
    }
    if ($name === 'generator') {
        $this->setGenerator($content);
    } elseif ($name === 'description') {
        $this->setDescription($content);
    } else {
        $this->_metaTags[$attribute][$name] = $content;
    }
    return $this;
}