تاریخ امروز:1 اردیبهشت 1403
آموزش سئو با لاراول

آموزش استفاده از پکیج SEOtools و بهبود سئو در لاراول

با سلام خدمت همه‌ی دوستان
میخوام در این پست آموزش استفاده از پکیج SEOtools و بهبود سئو در لاراول رو بدم خدمتتون. سعی می‌کنم ازین به بعد آموزش لاراول بیشتری بزارم خدمتتون.

نکته:‌من بر اساس لاراول 5.6 نوشتم این آموزش رو.
ابتدا این پکیج رو با استفاده از composer نصب می‌کنیم:

composer require artesaos/seotools

بعد تنظیماتش رو میاریم:

php artisan vendor:publish

حالا توی config/seotools.php می‌تونیم برخی تنظیماتش رو تغییر بدیم.
برای استفاده ازش ۲ روش هستش:
روش اول:
در ابتدای کنترل خودتون این رو بزنید:

use SEO;

حالا می‌تونید ازین گزینه‌ها استفاده کنید:

SEO::setTitle('Your Title');
SEO::setDescription('Your Description');
SEO::opengraph->setUrl('Site URL');
SEO::setCanonical('Page URL');
SEO::opengraph()->addProperty('type','articles');
SEO::twitter()->setTitle('Your Title');
SEO::twitter()->setSite('Twitter User');

روش دوم
در ابتدای کنترل خودتون این رو بزنید:

use SEOMeta;
use OpenGraph;
use Twitter;

حالا می‌تونید ازین گزینه‌ها استفاده کنید:

        SEOMeta::setTitle('Your Title');
        SEOMeta::setDescription('Your Description');
        SEOMeta::addMeta('article:published_time', 'Date Time', 'property');
        SEOMeta::addMeta('article:section', 'Category Name', 'property');
        SEOMeta::addKeyword(['key1', 'key2', 'key3']);

        OpenGraph::setDescription('Your Description');
        OpenGraph::setTitle('Your Title');
        OpenGraph::setUrl('SITE URL');
        OpenGraph::addProperty('type', 'article');
        OpenGraph::addProperty('locale', 'fa-ir');
        OpenGraph::addProperty('locale:alternate', [ 'en-us']);

        OpenGraph::addImage('Image Address');
        OpenGraph::addImage(['url' => 'Image Address', 'size' => 300]);
        OpenGraph::addImage('Image Address', ['height' => 300, 'width' => 300]);

برای کار کردن با opengraph ازین‌ها هم می‌تونید استفاده کنید:

        OpenGraph::setTitle('Article')
            ->setDescription('Some Article')
            ->setType('article')
            ->setArticle([
                'published_time' => 'datetime',
                'modified_time' => 'datetime',
                'expiration_time' => 'datetime',
                'author' => 'profile / array',
                'section' => 'string',
                'tag' => 'string / array'
            ]);

        // Namespace URI: http://ogp.me/ns/book#
        // book
        OpenGraph::setTitle('Book')
            ->setDescription('Some Book')
            ->setType('book')
            ->setBook([
                'author' => 'profile / array',
                'isbn' => 'string',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // Namespace URI: http://ogp.me/ns/profile#
        // profile
        OpenGraph::setTitle('Profile')
             ->setDescription('Some Person')
            ->setType('profile')
            ->setProfile([
                'first_name' => 'string',
                'last_name' => 'string',
                'username' => 'string',
                'gender' => 'enum(male, female)'
            ]);

        // Namespace URI: http://ogp.me/ns/music#
        // music.song
        OpenGraph::setType('music.song')
            ->setMusicSong([
                'duration' => 'integer',
                'album' => 'array',
                'album:disc' => 'integer',
                'album:track' => 'integer',
                'musician' => 'array'
            ]);

        // music.album
        OpenGraph::setType('music.album')
            ->setMusicAlbum([
                'song' => 'music.song',
                'song:disc' => 'integer',
                'song:track' => 'integer',
                'musician' => 'profile',
                'release_date' => 'datetime'
            ]);

         //music.playlist
        OpenGraph::setType('music.playlist')
            ->setMusicPlaylist([
                'song' => 'music.song',
                'song:disc' => 'integer',
                'song:track' => 'integer',
                'creator' => 'profile'
            ]);

        // music.radio_station
        OpenGraph::setType('music.radio_station')
            ->setMusicRadioStation([
                'creator' => 'profile'
            ]);

        // Namespace URI: http://ogp.me/ns/video#
        // video.movie
        OpenGraph::setType('video.movie')
            ->setVideoMovie([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // video.episode
        OpenGraph::setType('video.episode')
            ->setVideoEpisode([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array',
                'series' => 'video.tv_show'
            ]);

        // video.tv_show
        OpenGraph::setType('video.tv_show')
            ->setVideoTVShow([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // video.other
        OpenGraph::setType('video.other')
            ->setVideoOther([
                'actor' => 'profile / array',
                'actor:role' => 'string',
                'director' => 'profile /array',
                'writer' => 'profile / array',
                'duration' => 'integer',
                'release_date' => 'datetime',
                'tag' => 'string / array'
            ]);

        // og:video
        OpenGraph::addVideo('http://example.com/movie.swf', [
                'secure_url' => 'https://example.com/movie.swf',
                'type' => 'application/x-shockwave-flash',
                'width' => 400,
                'height' => 300
            ]);

        // og:audio
        OpenGraph::addAudio('http://example.com/sound.mp3', [
                'secure_url' => 'https://secure.example.com/sound.mp3',
                'type' => 'audio/mpeg'
            ]);

و برای توییتر:

Twitter::addValue($key, $value); // value can be string or array
Twitter::setType($type); // type of twitter card tag
Twitter::setTitle($type); // title of twitter card tag
Twitter::setSite($type); // site of twitter card tag
Twitter::setDescription($type); // description of twitter card tag
Twitter::setUrl($type); // url of twitter card tag
Twitter::addImage($url); // add image url

حالا برای نمایش در view می‌تونید به این طریق عمل می‌کنید:

اگه از روش اول استفاده کردین:

	{!! SEO::generate() !!}

اگه می‌خواین minify بشه:

	{!! SEO::generate(true) !!}

و برای روش دوم:

	{!! SEOMeta::generate() !!}
	{!! OpenGraph::generate() !!}
	{!! Twitter::generate() !!}

 

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *