composer require abdellahramadan/open-graph-bundle
Add {{ open_graph() }}
to the base template or any page where the meta information will be injected
In your controller, type-hint OpenGraphInterface
class HomeController extends AbstractController
{
public function index(OpenGraphInterface $openGraph): Response
{
$openGraph
->setTitle('My website')
->setDescription('Some descriptions ...')
->setSiteName('My Blog')
;
...
return $this-render('index.html.twig');
}
}
This will render
<meta property="og:title" content="My website">
<meta property="og:description" content="Some descriptions ...">
<meta property="og:site_name" content="My Blog">
$openGraph->addStructuredProperty('image', 'secure_url', 'https://mysite.com/test.jpg')
this will render
<meta property="og:image:secure_url" content="https://mysite.com/test.jpg" />
->addTwitterCardProperty('description', 'This is an example X(Twitter) Card
will render
<meta name="twitter:description" content="This is an example X(Twitter) Card)" />