Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wintercms/wn-seo-plugin
Plugin for managing SEO metadata in Winter CMS
https://github.com/wintercms/wn-seo-plugin
hacktoberfest plugin seo wintercms
Last synced: about 1 month ago
JSON representation
Plugin for managing SEO metadata in Winter CMS
- Host: GitHub
- URL: https://github.com/wintercms/wn-seo-plugin
- Owner: wintercms
- License: mit
- Created: 2022-08-14T06:26:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-20T16:46:22.000Z (10 months ago)
- Last Synced: 2024-04-14T05:41:28.765Z (8 months ago)
- Topics: hacktoberfest, plugin, seo, wintercms
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 9
- Watchers: 5
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wintercms - Winter.SEO - Easily manage SEO metadata. (Uncategorized / Uncategorized)
README
# SEO Plugin
Easily handle Search Engine Optimization in your Winter CMS projects. Inspired by https://github.com/bennothommo/wn-meta-plugin.
Future plans including support for easily generating structured data and automatically attaching SEO meta fields to CMS pages, Winter.Pages pages, & generically to any Winter CMS model. Check the TODO list in Plugin.php for more planned features.
## Installation
```bash
composer require winter/wn-seo-plugin
```Then add the `[seoTags]` component to your `` in your theme, ideally right after the standard encoding and responsiveness tags.
### Suggested implementation:
**Layout or header partial**:
```twig
{% partial "meta/seo" %}
```**`partials/meta/seo.htm`:**
```twig
[seoTags]
==
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');
}
?>
=={%- placeholder page_title default %}
{%- if raw_title %}{{ raw_title | striptags }}{% elseif page_title %}{{ page_title | striptags }} | {{ app_name }}{% else %}{{ app_name }}{% endif -%}
{% endplaceholder -%}{% 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.
## Usage
### Meta Tags
Use the `Meta` class to add `` tags that will be rendered by the `[seoTags]` component. Examples:
```php
use Winter\SEO\Classes\Meta;// Adds
Meta::set('og:type', 'article');// Appends a meta tag to the collection; allowing for full control of the
// attributes used as well as preventing it from being overridden and / or
// enabling multiple tags with the same name to be added.
Meta::append([
'name' => 'og:type',
'content' => 'article',
'example_attribute' => 'the_cake_is_a_lie',
]);// Overrides `og:type` because it was set later in the request
Meta::set('og:type', 'article');// Retreive a specific meta tag by its name
Meta::get('og:type');// Retrieve all meta tags currently set in this request
Meta::all()// Clear all previously set meta tags and start fresh from this point on in the request
Meta::refresh();
```### Link Tags
Use the `Link` class to add `` tags that will be rendered by the `[seoTags]` component. Examples:
```php
use Winter\SEO\Classes\Link;// Adds
Link::set('base_url', 'https://example.com');// Appends a link tag to the collection; allowing for full control of the
// attributes used as well as preventing it from being overridden and / or
// enabling multiple tags with the same name to be added.
Link::append([
'rel' => 'preload',
'href' => 'https://example.com/logo.png',
'as' => 'image',
]);// Overrides `base_url` because it was set later in the request
Link::set('base_url', url()->current());// Retreive a specific link tag by its name
Link::get('base_url');// Retrieve all link tags currently set in this request
Link::all()// Clear all previously set link tags and start fresh from this point on in the request
Link::refresh();
```