mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
DOCS Added 'Modifying Meta Tags' entry
This commit is contained in:
parent
d4e322b6da
commit
0cbc02add1
@ -143,6 +143,27 @@ $MetaTags(false)
|
|||||||
<title>$Title - Bob's Fantasy Football</title>
|
<title>$Title - Bob's Fantasy Football</title>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Modifying Meta Tags
|
||||||
|
|
||||||
|
You can override the `MetaComponents()` method on your `SiteTree` sub-classes or make use of the `MetaComponents` extension point to manipulate the underlying data that is rendered by `$MetaTags`. Example (for `Page` class):
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function MetaComponents()
|
||||||
|
{
|
||||||
|
$tags = parent::MetaComponents();
|
||||||
|
// Override the content of the Title tag (needs to be html)
|
||||||
|
if ($this->MetaTitle) {
|
||||||
|
$tags['title']['content'] = $this->obj('MetaTitle')->forTemplate();
|
||||||
|
}
|
||||||
|
// Provide a default Meta Description
|
||||||
|
if (!$tags['description']['attributes']['content']) {
|
||||||
|
// provide raw text as attributes will be escaped later
|
||||||
|
$tags['description']['attributes']['content'] = $this->dbObject('Content')->LimitCharactersToClosestWord(300);
|
||||||
|
}
|
||||||
|
return $tags;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
||||||
```ss
|
```ss
|
||||||
|
Loading…
x
Reference in New Issue
Block a user