Keyword

Opengraph Image tag not being rendered

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132653 by Mark Fallon
Opengraph Image tag not being rendered was created by Mark Fallon
Hi,

I am using K2 Version 2.6.8.

The other Opengraph tags are rendered fine (url, title, description & type) but there is no og:image tag, even though the K2 item has an image set.

Any ideas?

Thanks

Mark

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132654 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
Hello Mark,

Have you specified which image size you want to use?
This setting is located in K2's params.

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132655 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
Yes. Tried changing the size as well. No joy.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132656 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
Is there a link I can see?

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132657 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
For some reason it only seems to affect the site on my localhost. The live site works OK... strange.

Another related question: If there is no image in the article, how can I set a default og:image src?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132658 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
Facebook won't work on localhost.
Yes you can perform an if/else check in your template and if an image is not present you can use the setMetadata function docs.joomla.org/JDocument/setMetaData .

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132659 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
But what am I testing for? I can't run an if/else on the existence of an og:image tag, because wouldn't the template be loaded BEFORE K2? so there will never be an og:image tag at the time the if/else is executed.

I need to find the K2 file that sets the og:image tag so I can amend it. Have you any idea which file it is? I have searched through the file contents of the K2 folder to find "og:image" but no luck.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132660 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
You do not need to hack K2 core files.
You will lose all your changes when you update.

This has to be done via template overrides.
You need to check if the image is both set and present.

This post will help you on template overrides.
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132661 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
Yes. I know about template overrides. But I do not know which file to override, hence my question.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132662 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
It's the item.php file.

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132663 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
I can't find any reference to any of the Opengraph meta tags in item.php... can you be more specific?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132664 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
You do no need to find any reference.

You simply need to add a new metatag if an image is not present.

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132665 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
OK. I could have just done that anyway. I wanted to to keep my code clean by just editing it where K2 sets the meta tag but it seems we don't know where that is.

I have done it the way you suggested instead and although being quite a hacky way, it does work.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132666 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
It is not hacky.
You get to keep your edits even if you update K2.

If you tried the other way you would have to backup and re-patch K2 after every update.

Please Log in or Create an account to join the conversation.

  • Mark Fallon
  • Mark Fallon's Avatar Topic Author
  • Offline
  • New Member
More
10 years 7 months ago #132667 by Mark Fallon
Replied by Mark Fallon on topic Re: Opengraph Image tag not being rendered
I wanted to use template overrides to change the correct file and in the correct LOGICAL place.

Placing this code into a random place in a file that doesn't deal with the generation of the og meta tags, IS a hacky way of doing it.

It would make more sense to to edit the relevant code that generates the meta tags, in the relevant file (using a template override obviously), rather than just placing it in any old place in the item.php file.

But I suppose I like to keep my code neat and logical. Other people may not.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 7 months ago #132668 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Opengraph Image tag not being rendered
Exactly

Some people help you with your project for free while other may don't.
Anyway it works like this.

Either hack core files or change item.php
No other file can be overriden.

I am locking the topic now.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum