ARCANEDEV / SEO-Helper

:mag: SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).
MIT License
322 stars 49 forks source link

How to add OpenGraph & TwitterCards #45

Closed StanBarrows closed 6 years ago

StanBarrows commented 6 years ago

How to Add Open Graph and Twitter on Laravel?:

Heyho! First of all thanks for providing such an awesome package!

So far, I just was using the normal SEO-Types inside my Laravel App. But i'm not able to add Graph or Cards to it. What I'm missing out?

$this->seo()
     ->setTitle(Lang::get('meta.frontend.'.$page.'.title'))
     ->setDescription(Lang::get('meta.frontend.'.$page.'.description'))
     ->setKeywords([Lang::get('meta.frontend..'.$page.'.keywords')])
     ->setImage($page.  'seo.png');

Where I need to pass the Graph or Card Object to the view? If i just using this code I cant see the values inside my Laravel app.

$openGraph = new Graph;

$openGraph->setType('website');
$openGraph->setTitle('Your awesome title');
$openGraph->setDescription('Your awesome description');
$openGraph->setSiteName('Your site name');
$openGraph->setUrl('http://my.awesome-website.com');
$openGraph->setImage('http://my.awesome-website.com/img/cool-image.jpg');
$openGraph->render();

I tried to pass it into the setOpenGraph or setSeoTwitter Method, but thats somehow not working.

$this->seo()
     ->setTitle(Lang::get('meta.frontend.'.$page.'.title'))
     ->setDescription(Lang::get('meta.frontend.'.$page.'.description'))
     ->setKeywords([Lang::get('meta.frontend..'.$page.'.keywords')])
     ->setImage($page.  'seo.png')
     ->setSeoTwitter()
     ->setSeoOpenGraph($openGraph);

Thanks for an help, Stan

arcanedev-maroc commented 6 years ago

Did you tried something like this ?

$this->seo()
     ->setTitle(Lang::get('meta.frontend.'.$page.'.title'))
     ->setDescription(Lang::get('meta.frontend.'.$page.'.description'))
     ->setKeywords([Lang::get('meta.frontend..'.$page.'.keywords')])
     ->setImage($page.'seo.png');

$this->seo()->twitter(); // Call the twitter card methods

$this->seo()->openGraph()
     ->setType('website')
     ->setTitle('Your awesome title')
     ->setDescription('Your awesome description')
     ->setSiteName('Your site name')
     ->setUrl('http://my.awesome-website.com')
     ->setImage('http://my.awesome-website.com/img/cool-image.jpg');