2

I have this clien't site with Joomla 2.5 and K2 2.6.9. Yes, I know it should be updated but tell that to this 'cheap' client of mine. Nevertheless, it works flawlessly and client is happy with it for years.

But (there is always at least one 'but', right?) it has problems with sharing K2 items on Facebook! Sometimes they show wrong item's title to be shared and sometimes they miss item's main picture to be shared. I dont use any social sharing plugin on that site, but it has sh404SEF for SEF URLs and it's social features are enabled. Social sharing works OK for all other pages except for K2 items, that's why I am sure that K2 causes these problems. In K2 categories options I made sure to have all K2's social features disabled, but when I check K2 item's share through Open Graph Debugger it clearly shows duplicated OG tags.

How can I disable K2's Open Graph tags?

3

I had a somewhat similar problem recently. To fix it you need to hack one of the k2 core files.

//Go to(windows style path) joomla root/components/com_k2/views/item/view.html.php  
// and comment line from 445 to 455
/*
$document->setMetaData('og:url', $uri->toString());
        $document->setMetaData('og:title', htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8'));
        $document->setMetaData('og:type', 'Article');
        $facebookImage = 'image'.$params->get('facebookImage', 'Small');
        if ($item->$facebookImage && JFile::exists(JPATH_SITE.$item->$facebookImage))
        {
            $image = substr(JURI::root(), 0, -1).str_replace(JURI::root(true), '', $item->$facebookImage);
            $document->setMetaData('og:image', $image);
            $document->setMetaData('image', $image);
        }
        $document->setMetaData('og:description', htmlspecialchars(strip_tags($document->getDescription()), ENT_QUOTES, 'UTF-8'));
*/

For joomla root/components/com_k2/views/latest​/view.html.php

comment line from line 256 - 261
// Set Facebook meta data
/*
        $document = JFactory::getDocument();
        $uri = JURI::getInstance();
        $document->setMetaData('og:url', $uri->toString());
        $document->setMetaData('og:title', (K2_JVERSION == '15') ? htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8') : $document->getTitle());
        $document->setMetaData('og:type', 'website');
        $document->setMetaData('og:description', strip_tags($document->getDescription()));
*/

For joomla root/components/com_k2/views/itemlist/view.html.php  line 690 to 701

// Set Facebook meta data
/*
    $document = JFactory::getDocument();
        $uri = JURI::getInstance();
        $document->setMetaData('og:url', $uri->toString());
        $document->setMetaData('og:title', (K2_JVERSION == '15') ? htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8') : $document->getTitle());
        $document->setMetaData('og:type', 'website');
        if ($task == 'category' && $this->category->image && strpos($this->category->image, 'placeholder/category.png') === false)
        {
            $image = substr(JURI::root(), 0, -1).str_replace(JURI::root(true), '', $this->category->image);
            $document->setMetaData('og:image', $image);
            $document->setMetaData('image', $image);
        }
        $document->setMetaData('og:description', strip_tags($document->getDescription()));

*/

I found this solution on the JoomlaWorks forum Stop K2 from generating OG tags and the link it lists as a solution Com_k2 default open graph fix

There is a 3rd option which is much the same- k2-and-setting-the-wrong-open-graph-description-meta-tag

Hope it helps.

  • 1
    You saved my day, even though it involves editing core K2 files... Thank you... – Mikan Feb 10 '16 at 14:57
  • I don't like changing core files either, but sometimes it is only solution. You are welcome. – user7746 Feb 10 '16 at 15:10
  • 1
    @MikaLazic Good answer, but please try to provide the solution rather than linking to it (just in case the links ever die). I've added the code for you. – TryHarder Feb 10 '16 at 23:06
  • 1
    @moomoochoo Thank you for your edit and also for your kind suggestion. I will do that way in the future, just have to learn using markdown (I just found FAQ here stackoverflow.com/editing-help). – user7746 Feb 11 '16 at 8:23
  • 1
    Even though I was completely satified with the link only provided in the answer, @moomoochoo got the point. Thanks to both of you... – Mikan Feb 11 '16 at 8:52

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.