Artesaos\SEOTools\SEOMeta::generate PHP Method

generate() public method

Generates meta tags.
public generate ( boolean $minify = false ) : string
$minify boolean
return string
    public function generate($minify = false)
    {
        $this->loadWebMasterTags();
        $title = $this->getTitle();
        $description = $this->getDescription();
        $keywords = $this->getKeywords();
        $metatags = $this->getMetatags();
        $canonical = $this->getCanonical();
        $prev = $this->getPrev();
        $next = $this->getNext();
        $languages = $this->getAlternateLanguages();
        $html = [];
        if ($title) {
            $html[] = "<title>{$title}</title>";
        }
        if ($description) {
            $html[] = "<meta name=\"description\" content=\"{$description}\">";
        }
        if (!empty($keywords)) {
            $keywords = implode(', ', $keywords);
            $html[] = "<meta name=\"keywords\" content=\"{$keywords}\">";
        }
        foreach ($metatags as $key => $value) {
            $name = $value[0];
            $content = $value[1];
            // if $content is empty jump to nest
            if (empty($content)) {
                continue;
            }
            $html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\">";
        }
        if ($canonical) {
            $html[] = "<link rel=\"canonical\" href=\"{$canonical}\"/>";
        }
        if ($prev) {
            $html[] = "<link rel=\"prev\" href=\"{$prev}\"/>";
        }
        if ($next) {
            $html[] = "<link rel=\"next\" href=\"{$next}\"/>";
        }
        foreach ($languages as $lang) {
            $html[] = "<link rel=\"alternate\" hreflang=\"{$lang['lang']}\" href=\"{$lang['url']}\"/>";
        }
        return $minify ? implode('', $html) : implode(PHP_EOL, $html);
    }

Usage Example

Beispiel #1
0
 /**
  * @param $expectedString
  */
 protected function setRightAssertion($expectedString)
 {
     $expectedDom = $this->makeDomDocument($expectedString);
     $actualDom = $this->makeDomDocument($this->seoMeta->generate());
     $this->assertEquals($expectedDom->C14N(), $actualDom->C14N());
 }