Hi guys. I'm new at Magento. I'm going to make open graph meta tags inside the head tag. I made a custom phtml. I want to put title (og:title) and description (og:description) there. I have no idea how to make it dynamic. I want to make it the same as the current. Any variable to use? Thanks.
You can add dynamic title and description using custom phtml file,
Create Static block and call static block from phtml file,
Now you need to add your graph meta tag into Content -> Element -> Block
Call Block identifier using phtml file as per above link
I just want to make og:title is the same as the title by system and og:description is the same as the description by title. Could I do that in default_head_blocks.xml? How to access the title and the description variable and put them in default_head_blocks.xml? Thanks.
Isn't it better to use the extension for this?
There is the Magento 2 Facebook Open Graph Extension that allows you to set OG Title, description and image directly from the admin on any page you'd like to share be it the blog post, the product page, the cms page, etc.
and you don't need to have any technical skills to set the OG tags, they are set in the specifically created sections.
That's much easier than do the code thing. And this module works well not only on Facebook but any other social media like Twitter, Viber, What's up or other.