Jump to content
thirty bees forum
  • 0

Open graph tags


MockoB

Question

I'm trying to update my open graph tags recently but I have an issue with the blog images, so little help will be appreciated. Here is my code below: {if isset($meta_description) AND $meta_description} <meta name="description" property="og:description" content="{$meta_description|escape:'html':'UTF-8'}" /> {/if} <meta property="og:url" content="https://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}"/> <meta property="fb:app_id" content="12345678910"/> <meta property="og:site_name" content="{$shop_name|escape:'html':'UTF-8'}"/> <meta property="og:title" content="{$meta_title|escape:'html':'UTF-8'}"/> <meta property="og:type" content="{if $page_name == 'product'}product{elseif $page_name == 'blog-module'}article{else}website{/if}"/> {if $page_name == 'product'} <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'thickbox_default')|escape:'html':'UTF-8'}"/> <meta property="og:image:width" content="664"> <meta property="og:image:height" content="500"> <meta property="og:image:alt" content="{$meta_title|escape:'html':'UTF-8'}"> {elseif $page_name == 'blog-module'} <meta property="og:image" content="{$blog_article_img|escape:'html':'UTF-8'}"/> <meta property="og:image:width" content="713"> <meta property="og:image:height" content="356"> <meta property="og:image:alt" content="{$meta_title|escape:'html':'UTF-8'}"> {else} <meta property="og:image" content="https://your.site.here/img/logo.jpg"/> <meta property="og:image:width" content="1124"> <meta property="og:image:height" content="614"> <meta property="og:image:alt" content="{$shop_name|escape:'html':'UTF-8'}"> {/if} So my issue is with the blog module image property. It's fine if the shared link is the blog topic, but if I share my.site.com/blog the debugger tries to pickup the image I associated above. How could I assign image for the blog page (and categories) and separate image property for the articles.

PS: This code is working on PS 1.5.6.1 so it should be working on thirtybees most probably also. The only thing to change is your images width/height, the the link of the additional logo (I had to add instead the default one) and of course you should remove the blog mentions and associated code, or change it with your blog page name.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Thanks @lesley Everything is working great, just the image property for the blog is set wrong. Same thing is with topic property, so I will give example with it.

I need to associate both links below with blog property https://my.site.com/blog https://my.site.com/blog/category-number1 https://my.site.com/blog/category-number2 ...

And to associate all topics with topic property https://my.site.com/topic-number1 https://my.site.com/topic-number2 ...

Like I set it at the moment all links are associated with "topic" property, because I get the link from $page_name variable for the blog module. I need to specify different links like explained above for "blog" and "topic" properties.

There are specific parameters for categories and topics. I don't know if they could be distinguished by those parameters...

Link to comment
Share on other sites

  • 0

@yaniv14 just solved it! Thank you!

The reason for the issue is that the variable of the image of the blog is not used on the blog page itself and blog categories. It is used just on the article pages. So the code bellow checks if the variable is on the current page, if not, then serves the provided by me image:

or you could use {$logo_url} instead https://your.site.here/img/desiredimg.jpg in the above code. But usually the logo img width/height don't fit the facebook recommendations.

Link to comment
Share on other sites

  • 0
On 9/19/2018 at 1:35 PM, MockoB said:

{elseif $page_name == 'blog-module'} <meta property="og:image" content="{$blog_article_img|escape:'html':'UTF-8'}"/> <meta property="og:image:width" content="713"> <meta property="og:image:height" content="356"> <meta property="og:image:alt" content="{$meta_title|escape:'html':'UTF-8'}"> {else} <meta property="og:image" content="https://your.site.here/img/logo.jpg"/> <meta property="og:image:width" content="1124"> <meta property="og:image:height" content="614"> <meta property="og:image:alt" content="{$shop_name|escape:'html':'UTF-8'}"> {/if}

Hello.

In Niara, an article has the default meta description and og:image tags.

I'm trying to add one elseif $page_name== 'blog-module' to header.tpl, but it doesn't seems to work. I'm not sure if 'blog-module' is a correct value. I use this with 'product' to show product's image.

Now if you post a blog post to facebook, twitter, etc, it appears the shop logo and description, but nothing refers to the article.

Any recomendations? Thanks!

Link to comment
Share on other sites

  • 0

Great! Now with:

{elseif $page_name == 'module-beesblog-post'}

I can print the meta tags in blog posts! Here are my changes. When it's a product I show it's image, if it is a blog I set the image, twitter:title and description (I clean HTML tags, and truncate the article).

It should be part of header.tpl in Niara, don't you think?

{if $page_name=='product'}
        <meta property="og:image" content="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large')}">
        <meta name="twitter:title" content="{$meta_title|escape:'html':'UTF-8'}" />
{elseif $page_name == 'module-beesblog-post'}
        {assign var=imagePath value=Media::getMediaPath(BeesBlog::getPostImagePath($post->id))}
       {if ($imagePath)}
           <meta property="og:image" content="{$imagePath|escape:'html':'UTF-8'}"/>
       {/if}
       <meta name="description" content="{$post->content|strip_tags:true|escape:'htmlall':'UTF-8'|truncate:450}" />
       <meta name="twitter:title" content="{$post->title|escape:'htmlall':'UTF-8'}" />
{else}
    <meta name="twitter:description" content="<SHOP DESCRIPTION.>" />
    <meta property="og:image" content="<SHOP-LOGO-URL>" />
    <meta name="twitter:title" content="{$meta_title|escape:'html':'UTF-8'}" />

 

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...