Skip to content

Commit

Permalink
Add example usage in a meta/seo partial
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers committed Feb 4, 2024
1 parent aed97a8 commit 397307e
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,79 @@ composer require wintercms/wn-seo-plugin

Then add the `[seoTags]` component to your `<head>` in your theme, ideally right after the standard encoding and responsiveness tags.

### Suggested implementation:

**Layout or header partial**:
```twig
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% partial "meta/seo" %}
</head>
```

**`partials/meta/seo.htm`:**
```twig
[seoTags]
==
<?php
use Backend\Models\BrandSetting;
use System\Classes\MediaLibrary;
use Winter\SEO\Classes\Link;
use Winter\SEO\Classes\Meta;
function onStart()
{
$this['page_title'] = $this->page->title ?? Meta::get('og:title') ?? '';
$this['app_name'] = BrandSetting::get('app_name');
// Set the cannonical URL
Link::set('canonical', \URL::current());
// Parse the meta_image as a media library image
if (!empty($this->page->meta_image)) {
$this->page->meta_image = MediaLibrary::url($this->page->meta_image);
}
// Handle the nofollow meta property being set
if (!empty($this->page->meta_nofollow)) {
Link::set('robots', 'nofollow');
}
// Set the meta tags based on the current page if not set
$metaMap = [
Meta::class => [
'og:title' => 'meta_title',
'og:description' => 'meta_description',
'og:image' => 'meta_image',
],
Link::class => [
'prev' => 'paginatePrev',
'next' => 'paginateNext',
],
];
foreach ($metaMap as $class => $map) {
foreach ($map as $name => $pageProp) {
if (!empty($this->page->{$pageProp}) && empty($class::get($name))) {
$class::set($name, $this->page->{$pageProp});
}
}
}
$this['raw_title'] = Meta::get('title');
}
?>
==
<title>
{%- placeholder page_title default %}
{%- if raw_title %}{{ raw_title | striptags }}{% elseif page_title %}{{ page_title | striptags }} | {{ app_name }}{% else %}{{ app_name }}{% endif -%}
{% endplaceholder -%}
</title>
{% component seoTags %}
```

## Configuration

Configuration for this plugin is handled through a [configuration file](https://wintercms.com/docs/plugin/settings#file-configuration). In order to modify the configuration values and get started you can copy the `plugins/winter/seo/config/config.php` file to `config/winter/seo/config.php` and make your changes there.
Expand Down

0 comments on commit 397307e

Please sign in to comment.