notes for Modify metatags in silverstripe:
put this in Page.php (Page extends SiteTree)
public function MetaTags($includeTitle = true) { $tags = ""; if($this->MetaDescription) { $tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n"; } if($this->ExtraMeta) { $tags .= $this->ExtraMeta . "\n"; } $this->extend('MetaTags', $tags); return $tags; }
put this in page.ss
<!DOCTYPE html> <html lang="<% sprintf(_t('IMAGE','%2.2s'),$Locale.RFC1766) %>"> <head> <% base_tag %> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title>$Title • $SiteConfig.Title</title> $MetaTags() <link rel="stylesheet" href="{$ThemeDir}/css/style.css" /> </head> <body> ...
src
open cms/code/model/SiteTree.php
copy MetaTags function
page.php
extend SiteTree in Page.php with MetaTags(...) function
templates
$MetaTags(false) -> kein <titel></titel> $MetaTags -> mit <titel></titel>
custom metatags info
<meta name="language" content="en-uk"> -> useless! google uses only content: <html lang="en"><head>... <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> -> deprecated, use: <meta charset="utf-8"> instead <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> -> just delete this tag to make it visitble again
Alternative:
mit variables und kein $MetaTags in template
metatitle: $MetaTitle title: $Title metadescription: $MetaDescription metakeywords: $MetaKeywords customMeta: $ExtraMeta Nachteil: kein Feld fuer Generator usw... so just customized sitetree.php