PHP code example of winter / wn-seo-plugin

1. Go to this page and download the library: Download winter/wn-seo-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

winter / wn-seo-plugin example snippets


use Winter\SEO\Classes\Meta;

// Adds <meta name="og:type" content="article">
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();

use Winter\SEO\Classes\Link;

// Adds <link rel="base_url" rel="https://example.com">
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();
twig
[seoTags]
==

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');
}