2

When I post a link to Facebook I get the HTML code of the title showing in the post. As per this screenshot : http://prntscr.com/e858be

Can anyone advise why and if there is a way to stop this from happening ?

I am using Magento 2. The site is http://www.cellar2door.com/ and the link I was posting was http://cellar2door.com/thorn-clarke-terra-barossa-cabernet-sauvignon.html

2 Answers 2

0

If you take a look at your source code and more particulary to the meta tag og:description the HTML tags are escaped. This is refering to the OpenGraph Description by Facebook

<meta property="og:description" content="&lt;h2&gt;Details&lt;/h2&gt;
&lt;div class=&quot;std&quot;&gt;&lt;p&gt; Regional Barossa and Eden Valley wines, grown on family owned vineyards with the utmost care taken from the vineyards to the bottle. This ensures every customers purchase a bottle of Thorn-Clarke wine, they know where it is from, the care taken and the outstanding quality and value offered.


&lt;/p&gt;

&lt;p&gt; 
The 2011 Terra Barossa Cabernet Sauvignon has aromas of green bean, dried herbs, and dusty cedar like oak. The palate has a lively blackcurrant character on the front palate. This fruity character is balanced by spicy, chocolatey oak. The wine has varietal grainy tannins which are persistent well after the wine has left the mouth.
&lt;/p&gt;

&lt;p&gt;Current Vintage 2011&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vintages may vary from time to time and when delivered. Every effort is made to ensure the current vintage is displayed, however variations can occur.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
" />

There is an actual opened issue for that on Magento 2 Github : https://github.com/magento/magento2/issues/6776
You can upvote the issue on Github to put it forward.


If you want to do a temporary fix you can override the template and use the fix explained in the issue

$block->stripTags() is missing in vendor\magento\module-catalog\view\frontend\templates\product\view\opengraph\general.phtml

How to override template: http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-inherit.html#theme-inherit-templates


EDIT
1/ Copy the content of the file vendor/magento/module-catalog/view/frontend/templates/product/view/opengraph/general.phtml in your theme directory app/design/{Package}/{theme}/Magento_Catalog/templates/product/view/opengraph/general.phtml.
In that way you wil override Core template.

2/ Change the line

<meta property="og:description" content="<?php echo $block->escapeHtml($block->getProduct()->getShortDescription()); ?>" />

By (I add the $block->stripTags())

<meta property="og:description" content="<?php echo $block->escapeHtml($block->stripTags($block->getProduct()->getShortDescription())); ?>" />
6
  • Thanks Matthéo. I have contacted the template developer to see if they have a simple fix that I might be able to do myself as can't quite understand how to do what you suggested above. My other thought was to see if I could just put the word Details into the template above where the text i enter in the product appears so that I don't have to add the html for the bold and heading details; or would that just mean that the html from the first line of text would then show instead? Commented Feb 13, 2017 at 16:55
  • Hi @JamesWeston I edit my answer to give you the steps to process for fixing the issue. tell me if that is OK for you. Commented Feb 13, 2017 at 20:36
  • Hi @MatthéoGeoffray many thanks for breaking it down for me to a way that I can understand. Unfortunately I can't find the file to paste the code into. I can't find app/design/{Package}/{theme}/Magento_Catalog/templates/product/view/opengraph/general.phtml normally when I cannot find a file I do a search. When I searched general.phtml only one file is found and that is the first one that you guided me to to copy the code from. Commented Feb 14, 2017 at 0:50
  • Hi Matthew the template developer got back to be and it was as follows: your custom theme, you can make overwrite the template file at: vendor/magento/module-catalog/view/frontend/templates/product/view/opengraph/general.phtm So apparently I just had to overwrite it there. Many thanks for pointing me in the right direction. Jim Commented Feb 14, 2017 at 5:40
  • The file app/design/{Package}/{theme}/Magento_Catalog/templates/product/view/opengraph/general.phtml do not exist yet you have to create it. I highly recommended you to not change the file vendor/magento/module-catalog/view/frontend/templates/product/view/opengraph/general.phtml by editing the Core at the next update you will erase these changes. Commented Feb 14, 2017 at 8:35
0

You need Facebook's Open Graph meta tags for the shares/likes to properly display product information on Facebook.

Try this extension:

http://www.magentocommerce.com/magento-connect/socialshare-open-graph-3111.html

or, you can simply implement it yourself:

http://www.magentocommerce.com/boards/viewthread/304843/

1
  • It is already implemented in Magento 2, this is an actual issue Commented Feb 13, 2017 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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