- Posts: 17
COMMUNITY FORUM
Facebook og:image not loading
- Adrian Diehm
- Topic Author
- Offline
- New Member
Less
More
8 years 22 hours ago #159351
by Adrian Diehm
Facebook og:image not loading was created by Adrian Diehm
Facebook will not parse the og:image the first time a page is shared on Facebook - The solution to this is to include the og:image:width and og:image:height in the metadata. By default K2 does not include these 2 open graph parameters.
see "Pre Caching Images" here developers.facebook.com/docs/sharing/best-practices
Here is the fix for K2
/public_html/components/com_k2/views/item/view.html.php
After line 589 - insert the folllowing :
list($width, $height) = getimagesize($image);
$document->setMetaData('og:image:width', $width, 'property');
$document->setMetaData('og:image:height', $height, 'property');
/public_html/components/com_k2/views/itemlist/view.html.php
After line 738 - insert the folllowing :
list($width, $height) = getimagesize($image);
$document->setMetaData('og:image:width', $width, 'property');
$document->setMetaData('og:image:height', $height, 'property');
Note: This will only work with J3.6 or latter where you can add 'property' attribute using setMetaData. If you don't add 'property, then setMetaData will add a "Meta name=" rather than a "Meta property=" to the document - OG requires "Meta property="
see "Pre Caching Images" here developers.facebook.com/docs/sharing/best-practices
Here is the fix for K2
/public_html/components/com_k2/views/item/view.html.php
After line 589 - insert the folllowing :
list($width, $height) = getimagesize($image);
$document->setMetaData('og:image:width', $width, 'property');
$document->setMetaData('og:image:height', $height, 'property');
/public_html/components/com_k2/views/itemlist/view.html.php
After line 738 - insert the folllowing :
list($width, $height) = getimagesize($image);
$document->setMetaData('og:image:width', $width, 'property');
$document->setMetaData('og:image:height', $height, 'property');
Note: This will only work with J3.6 or latter where you can add 'property' attribute using setMetaData. If you don't add 'property, then setMetaData will add a "Meta name=" rather than a "Meta property=" to the document - OG requires "Meta property="
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 2 hours ago #159361
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Facebook og:image not loading
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Adrian Diehm
- Topic Author
- Offline
- New Member
Less
More
- Posts: 17
7 years 9 months ago #160410
by Adrian Diehm
Replied by Adrian Diehm on topic Facebook og:image not loading
A further Improvement:
Where the K2 category has no image there needs to be a default image loaded for Facebook
In the file : /public_html/components/com_k2/views/itemlist
after line 739 insert the following code
else
{
$image = $uri->toString().'images/facebook-like.jpg';
$document->setMetaData('og:image', $image);
$document->setMetaData('image', $image);
}
list($width, $height) = getimagesize($image);
$document->setMetaData('og:image:width', $width, 'property');
$document->setMetaData('og:image:height', $height, 'property');
This will load the specified file "facebook-like.jpg" from the "images" folder if the K2 Category has no image
It also appends the og:image:width and og:image:height for either scenario
Where the K2 category has no image there needs to be a default image loaded for Facebook
In the file : /public_html/components/com_k2/views/itemlist
after line 739 insert the following code
else
{
$image = $uri->toString().'images/facebook-like.jpg';
$document->setMetaData('og:image', $image);
$document->setMetaData('image', $image);
}
list($width, $height) = getimagesize($image);
$document->setMetaData('og:image:width', $width, 'property');
$document->setMetaData('og:image:height', $height, 'property');
This will load the specified file "facebook-like.jpg" from the "images" folder if the K2 Category has no image
It also appends the og:image:width and og:image:height for either scenario
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 9 months ago #160421
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Facebook og:image not loading
Nice one Adrian,
Kudos :)
Kudos :)
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Adrian Diehm
- Topic Author
- Offline
- New Member
Less
More
- Posts: 17
7 years 9 months ago #160431
by Adrian Diehm
Replied by Adrian Diehm on topic Facebook og:image not loading
Thanks for the positive response.
I have one more scenario to tackle with the K2 category image. I usually make the category image have small dimensions ie less than the 200px x 200px minimum requirement set by Facebook.
I'd like to store 2 category images, one that's used as per standard K2 and a Larger one just for FB but that sounds like a major alteration that will impact many core files. I may have to settle for using a default image if the category image is too small. which im sure I can code in exactly where these changes are made.
I think a solution to address these FB foibles is something the K2 Development team should consider in the next release of K2
I have one more scenario to tackle with the K2 category image. I usually make the category image have small dimensions ie less than the 200px x 200px minimum requirement set by Facebook.
I'd like to store 2 category images, one that's used as per standard K2 and a Larger one just for FB but that sounds like a major alteration that will impact many core files. I may have to settle for using a default image if the category image is too small. which im sure I can code in exactly where these changes are made.
I think a solution to address these FB foibles is something the K2 Development team should consider in the next release of K2
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 9 months ago #160447
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Facebook og:image not loading
Since 200px is not a really large image, loading only the category's image and using CSS in order to downscale it a bit will not impact your site's performance imho.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- spock
- Offline
- Junior Member
Less
More
- Posts: 26
7 years 1 month ago #164476
by spock
Replied by spock on topic Facebook og:image not loading
Work fine?
I don't see te new og: image: width/heigh tag
I don't see te new og: image: width/heigh tag
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 1 month ago #164498
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Facebook og:image not loading
In K2's parameters you can choose which image size you 're going to use for Facebook.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.