PHP code example of timurturdyev / simple-seo

1. Go to this page and download the library: Download timurturdyev/simple-seo 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/ */

    

timurturdyev / simple-seo example snippets


seo()->title('Кресло руководителя EX-500')
    ->description('Эргономичное кресло с кожаным сиденьем.')
    ->image('https://example.com/chair.jpg')
    ->canonical('https://example.com/catalog/chairs/ex-500');

seo()->meta()->noindex()->maxSnippet(120)->alternate('ru', 'https://example.com/ru');
seo()->openGraph()->type('article')->property('article:published_time', $date);
seo()->twitterCard()->card(TwitterCardType::SummaryLargeImage)->creator('@author');
seo()->jsonLd()->add(['@type' => 'WebSite', 'name' => 'Example']);

final class Product extends Model implements HasSeo
{
    public function toSeo(): SeoData
    {
        return new SeoData(
            title: $this->name,
            description: $this->summary,
            image: $this->cover_url,
            canonical: route('products.show', $this),
            ogType: 'product',
            jsonLd: [Schema::product()->name($this->name)->sku($this->sku)],
        );
    }
}

seo()->apply($product);

use TimurTurdyev\SimpleSeo\JsonLd\JsonLdBuilder;
use TimurTurdyev\SimpleSeo\Meta\MetaBuilder;
use TimurTurdyev\SimpleSeo\OpenGraph\OpenGraphBuilder;
use TimurTurdyev\SimpleSeo\SeoManager;
use TimurTurdyev\SimpleSeo\TwitterCard\TwitterCardBuilder;

$seo = new SeoManager(
    new MetaBuilder(defaultTitle: 'Мой сайт', titleSuffix: ' - Мой сайт'),
    new OpenGraphBuilder(defaultSiteName: 'Мой сайт', defaultType: 'website', defaultLocale: 'ru_RU'),
    new TwitterCardBuilder(),
    new JsonLdBuilder(),
);

<head>
    <?= $seo->render() 

use TimurTurdyev\SimpleSeo\JsonLd\Schema\Schema;

seo()->jsonLd()->add(
    Schema::product()
        ->name('EX-500')
        ->offers(Schema::offer()->price('49900.00')->priceCurrency('RUB')->inStock())
);

seo()->jsonLd()->add(
    Schema::breadcrumbs()
        ->item('Главная', 'https://example.com')
        ->item('Каталог', 'https://example.com/catalog')
        ->item('Кресла')
);

seo()->jsonLd()->add(
    Schema::qaPage()->question(
        Schema::question()
            ->name('Как выбрать кресло руководителя?')
            ->author('Иван')
            ->acceptedAnswer(
                Schema::answer()->text('Смотрите на механизм качания.')->upvoteCount(12)
            )
            ->suggestedAnswer(Schema::answer()->text('Берите с поясничным упором.'))
    )
);

seo()->title($title)->description($description)->canonical(request()->url());

seo()->jsonLd()->fromPage('Product', [
    'offers' => $product->type === 'product'
        ? Schema::offer()->price($minPrice)->priceCurrency('RUB')->inStock()
        : null,
]);
bash
php artisan vendor:publish --tag=simple-seo-config