- Posts: 8
COMMUNITY FORUM
Twitter card & Facebook Open Graph to K2 articles
- Robert
-
Topic Author
- Offline
- New Member
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Can you send me a link to the site?
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- STEPHAN HERBY
-
- Offline
- Premium Member
- Posts: 91
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).
- 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 :Add lines :
$document->setMetaData('og:description', strip_tags($document->getDescription()));
// 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
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.
Please Log in or Create an account to join the conversation.
- Robert
-
Topic Author
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- STEPHAN HERBY
-
- Offline
- Premium Member
- Posts: 91
Do you have any link ? Maybe there's another plugin activated like CoalaSocialLink ?
Please Log in or Create an account to join the conversation.
- Robert
-
Topic Author
- Offline
- New Member
- Posts: 8
When I test the link from developers.facebook.com/tools/debug/
it is the title of the site and the description of the site which appear in the fields og: title and og: description
The code that handles these items is just above the code you added to me earlier. Surely there is a way to change that in the file?
Please Log in or Create an account to join the conversation.
- STEPHAN HERBY
-
- Offline
- Premium Member
- Posts: 91
Anyway... I didn't change anything for Facebook Meta, I just added the Meta for Twitter Card and everythings work well for me on all my K2 items. This is why i asked you if there's any 3rd party extension installed to manage Meta ?
I have already noticed that sometimes default META insert in Joomla configuration are used instead of K2 items. maybe could you try to empty Joomla general META in configuration and see if then K2 item Meta are display ?
If then, let Joomla configuration general META empty, so k2 items META will be used instead. And place some META manually on all menu links where it is needed ? That's what I usually do...
Please Log in or Create an account to join the conversation.
- Robert
-
Topic Author
- Offline
- New Member
- Posts: 8
www.cabcl-association.com/site/medias/toute-l-actualite/item/851-club-demba-bamba-avec-france-u20-pour-preparer-un-crunch-decisif
When I test the link from developers.facebook.com/tools/debug/
it is the title of the site and the description of the site which appear in the fields og: title and og: description
The code that handles these items is just above the code you added to me earlier. Surely there is a way to change that in the file?
Please Log in or Create an account to join the conversation.
- STEPHAN HERBY
-
- Offline
- Premium Member
- Posts: 91
So when I have a look at the code, I can see that META OpenGraph from K2 are there and with the good content (Title, description, etc...).
<meta property="og:url" content="https://www.cabcl-association.com/site/medias/toute-l-actualite/item/851-club-demba-bamba-avec-france-u20-pour-preparer-un-crunch-decisif">
<meta property="og:title" content="CA Brive Rugby #Formation - CLUB : Demba BAMBA avec France U20 pour préparer un Crunch décisif.">
<meta property="og:type" content="article">
<meta property="og:image" content="https://www.cabcl-association.com/site/media/k2/items/cache/6ffa065634b02c07506d37e072a9ff8b_M.jpg">
<meta name="image" content="https://www.cabcl-association.com/site/media/k2/items/cache/6ffa065634b02c07506d37e072a9ff8b_M.jpg">
<meta property="og:description" content="L’encadrement tricolore a retenu 32 joueurs pour préparer un Crunch décisif. La préparation du match de l’Angleterre se fera en deux moments distincts...">
But there's a second Meta OpenGraph at the end of the header with the Title and description of the website. As it is the last one, Facebook take that one for filling his fields...
<meta property="og:url" content="https://www.cabcl-association.com/site/">
<meta property="og:image" content="https://www.cabcl-association.com/site/templates/rt_hadron/images/logo/logo-og.png">
<meta property="og:title" content="CA Brive Rugby #Formation">
<meta property="og:description" content="Site officiel de la formation du CA Brive Rugby.
Toute l'actualité et les résultats des jeunes du CABCL.">
PS : J'aime le rugby et j'aurais pu continuer en français, mais bon :)
Please Log in or Create an account to join the conversation.
- Robert
-
Topic Author
- Offline
- New Member
- Posts: 8
J'ai toujours le problème avec l'open graph Facebook au niveau du titre des articles. C'est le titre du site qui est récupéré et non celui de l'article. J'ai pu résoudre le problème de la description en supprimant la description du site et en l'insérant dans le lien du menu de la page d'accueil. Nous n'utilisons pas de module supplémentaire pour gérer les méta.
Merci.
Please Log in or Create an account to join the conversation.
- STEPHAN HERBY
-
- Offline
- Premium Member
- Posts: 91
Comme je te le disais plus haut, les META tag OG de K2 sont bons. ce qui pose problème c'est cette série de 2e META Tag OG qui apparaissent après les scripts dans le header (est-ce que tu les vois ?).
de plus le fait d'avoir effacer la META description n'a pas fait disparaitre ce 2e META OG, elle est juste vide et du coup Facebook prend en considération celle de K2 (tu me suis ?)
Mais le titre reste effectivement faux, mais pas seulement : l'URL également est celle de base du site et non pas celle de ton article.
Je me demande si ça ne vient pas de ton template ?
Tu devrais peut-être essayer d'installer ton site sur un serveur local genre MAMP et d'activer un template différent (genre celui d'origine de Joomla) juste pour voir si les tags seraient bons (ou d'activer un template momentanément sur ton site en production, juste le temps de voir ?) SI c'est le cas, ce serait bien à cause du template...
Please Log in or Create an account to join the conversation.
- George Nasis
-
- Offline
- Elite Member
- Posts: 214
thank you Stephan for your solution about twitter, it worked!
But indeed now the image in Facebook is not displayed :(
any idea?
thank you
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The og image is being automatically added, if you try to add it again then the wrong image will be displayed.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.