Category: English K2 Community
Hi Robert,
I have met this issue with Twitter Card. I had to hack one file in K2 to have Facebook AND Twitter Card propely display. Krikor will probably say (and with reason :)
DO NEVER HACK A CORE FILE.
But I didn't find another solution. SO this is How I did the trick :
K2 - Parameters - Go to K2 component
- Go to tab "Social"
- Make sure "Enable Facebook meta tags" is on "Yes" and choose your Image size for "og:image" (I choose Medium for example).
Hack file - Find file : component -> com-k2 -> models -> item.php
- Open it with a text editor (Coda for me i.e.)
- Find line 565 :
// Set Facebook meta data
- After lines 593 :
$document->setMetaData('og:description', strip_tags($document->getDescription()));
Add lines : // Hack - Set Twitter meta data if FB = 1 $document->setMetaData('twitter:card', 'summary_large_image'); $document->setMetaData('twitter:site', '@yourtwitteraccount'); $document->setMetaData('twitter:creator', '@yourtwitteraccount'); $document->setMetaData('twitter:url', $uri->toString()); $document->setMetaData('twitter:title', (K2_JVERSION == '15') ? htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8') : $document->getTitle()); $document->setMetaData('twitter:description', strip_tags($document->getDescription())); $document->setMetaData('twitter:image', $image); }
- Et voilà ! Twitter Card are now display in your header in each K2 item
Hope this help .
Don't forget to replace "@yourtwitteraccount" by your Twitter account of course.
Don't forget to make a backup of the file concerned BEFORE making your hack, in case you do something wrong.