Page 1 of 1

CGBlog and OG Tags

Posted: Wed Feb 27, 2019 5:39 am
by rbaby
I have an image field in my blog that I'd like to use as the og:image and use the summary description that's truncated for the og:description field.

What do I need to set on my page template <head> and what do I need to set on my CGBlog detail template? Any guidance would be appreciated.

This is currently the custom field I have for the image I'd like to use for the OG:Image.

{$entry->file_location}/{$entry->fieldsbyname.870x300->value}

Thank you for your time.

Re: CGBlog and OG Tags

Posted: Wed Feb 27, 2019 2:49 pm
by DIGI3
In CGBlog you need to assign it to a variable with global scope, so something like:

Code: Select all

{if $entry->fieldsbyname.870x300}
{$ogimage="{$entry->file_location}/{$entry->fieldsbyname.870x300->value}" scope=global}
{/if}
Then in your master page template head:

Code: Select all

{if $ogimage}
<meta property="og:image" content="{$ogimage}" />
{/if}
You can also set a default instead of testing for it, so:

Code: Select all

<meta property="og:image" content="{$ogimage|default:'url/image.jpg'}" />

Re: CGBlog and OG Tags

Posted: Wed Feb 27, 2019 4:57 pm
by Rolf

Re: CGBlog and OG Tags

Posted: Thu Feb 28, 2019 12:37 am
by rbaby
Thank you, I was struggling a bit with the cgblog templates and the primary templates. This helps immensely, I was doing the same thing (I thought) but it wasn't working so I will try with your example.