Skip to content

Instantly share code, notes, and snippets.

@webbower
Created March 28, 2012 02:13
Show Gist options
  • Save webbower/2222888 to your computer and use it in GitHub Desktop.
Save webbower/2222888 to your computer and use it in GitHub Desktop.
SilverStripe Page::MetaTags override
<?php
public function MetaTags($includeTitle = true) {
$tags = "";
if($includeTitle === true || $includeTitle == 'true') {
$tags .= HTML::tag('title', Convert::raw2xml(($this->MetaTitle) ? $this->MetaTitle : $this->Title)) . "\n";
}
$charset = ContentNegotiator::get_encoding();
if(HTML::is_html5()) {
$tags .= HTML::tag('meta', '', array('charset' => $charset)) . "\n";
} else {
$tags .= HTML::tag('meta', '', array(
'http-equiv' => 'Content-Type',
'content' => "text/html; charset=$charset",
)) . "\n";
}
if($this->MetaKeywords) {
$tags .= HTML::tag('meta', '', array(
'name' => 'keywords',
'content' => Convert::raw2att($this->MetaKeywords),
)) . "\n";
}
if($this->MetaDescription) {
$tags .= HTML::tag('meta', '', array(
'name' => 'description',
'content' => Convert::raw2att($this->MetaDescription),
)) . "\n";
}
if($this->ExtraMeta) {
$tags .= $this->ExtraMeta . "\n";
}
$this->extend('MetaTags', $tags);
return $tags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment