0

In order to add the following meta tags to the home page I have done the followings:

<meta property="og:image" content="https://example.com/media/wysiwyg/abc.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="512">
<meta property="og:image:height" content="512">
<meta name="title" property="og:title" content="My title">
  1. I have created cms_index_index_selectable_home_Image.xmland cms_page_view_selectable_home_Image.xml under app/design/frontend/<them_vendor>/<theme_dir>/Magento_Cms/layout/
  2. These are the contents of the XML files:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="head">
        <block name="facebookmeta" template="facebookmeta.phtml"/>
    </referenceContainer>
   </page>
  1. I have created facebookmeta.phtml under app/design/frontend/<them_vendor>/<theme_dir>/Magento_Cms/templates/ and these are the contents:
<meta property="og:image" content="https://example.com/media/wysiwyg/abc.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="512">
<meta property="og:image:height" content="512">
<meta name="title" property="og:title" content="My title">
  1. Under Content > Settings > Pages I have selected the home page and in the Design tab, in the Custom Layout Update field I have chosen Image.

I am using the Facebook Sharing Debugger Tool but the thumbnail image for the home page is not the one specified.

5
  • I think facebook taking first image of your site May 25 at 14:15
  • same happening in my case too.. I tried but got no luck May 25 at 14:19
  • @GohilRajesh Yes it is taking the first image, the solution is to explicitly define the image and that can happen with adding a meta tag to the head which can be done through custom layout XML. May 25 at 17:36
  • @GohilRajesh the part where I am confused is referencing the template file in the layout XML file because the tags can not be directly added to the layout XML file. May 25 at 17:39
  • Add through template file and call in xml or directly add code in xml both is same. May 26 at 3:14
1

A simpler way, if you just wanted these tags on the home page, would be to programmatically add these meta tags to your app/design/frontend/<them_vendor>/<theme_dir>/Magento_Theme/layout/cms_index_index.xml file:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <meta name="og:image" content="https://example.com/media/wysiwyg/abc.png">
        <meta name="og:image:type" content="image/png">
        <meta name="og:image:width" content="512">
        <meta name="og:image:height" content="512">
        <meta name="og:title" content="My title">
    </head>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.