Jump to content

Open Graph


kiwi

Recommended Posts

Could someone please help with this.

I've added this open graph code between the head section of the main.php file and it works as it should.

        {if $PRODUCT}
        <meta property="og:title" content="{$META_TITLE}">
        <meta property="og:image" content="{$PRODUCT.thumbnail}">
        <meta property="og:url" content="{$VAL_SELF}">
        {/if}

But what I'm trying to work out is how to add the product description?

<head>
        <title>{$META_TITLE}</title>
        {include file='templates/element.meta.php'}
        <link href="{$CANONICAL}" rel="canonical">
        <link href="{$ROOT_PATH}favicon.ico" rel="shortcut icon" type="image/x-icon">
        {include file='templates/element.css.php'}
        {include file='templates/content.recaptcha.head.php'}
        {include file='templates/element.google_analytics.php'}
        {include file='templates/element.js_head.php'}
        {if $PRODUCT}
        <meta property="og:title" content="{$META_TITLE}">
        <meta property="og:image" content="{$PRODUCT.thumbnail}">
        <meta property="og:url" content="{$VAL_SELF}">
        {/if}
    </head>

Link to comment
Share on other sites

The complete description? Or maybe you can use the short description?

The template variable {$PRODUCT.description} or {$PRODUCT.description_short} could be used.

Better might be:

{$PRODUCT.description_short|escape|strip_tags:false}

 

Link to comment
Share on other sites

Thanks for the help I tried these variable {$PRODUCT.description} and  {$PRODUCT.description_short} and they didn't work but this one did {$PRODUCT.description_short|escape|strip_tags:false} 

<meta property="og:description" content="{$PRODUCT.description_short|escape|strip_tags:false}">

But it shows the p tags, I tried this, strip_tags:true with no luck "{$PRODUCT.description_short|escape|strip_tags:true}" any ideas?

 opengraph.PNG

Thanks for your help it's appreciated.

Edited by kiwi
Link to comment
Share on other sites

I am thinking that the 'escape' is converting certain characters to their HTML entity (< to &lt;), which means strip_tags no longer sees them.

So try reversing the order: {$PRODUCT.description_short|strip_tags:false|escape}

But I fear that attempting to strip the tags first may inadvertently catch angle brackets that are not tags.

So beware.

 

 

Link to comment
Share on other sites

That work a treat, Thanks for the help, much appreciated.

For those interested this is what's in my main.php <head>

<head>
        <title>{$META_TITLE}</title>
        {include file='templates/element.meta.php'}
        <link href="{$CANONICAL}" rel="canonical">
        <link href="{$ROOT_PATH}favicon.ico" rel="shortcut icon" type="image/x-icon">
        {include file='templates/element.css.php'}
        {include file='templates/content.recaptcha.head.php'}
        {include file='templates/element.google_analytics.php'}
        {include file='templates/element.js_head.php'}
        {if $PRODUCT}
        <meta property="og:title" content="{$META_TITLE}">
        <meta property="og:description" content="{$PRODUCT.description_short|strip_tags:false|escape}">
        <meta property="og:image" content="{$PRODUCT.thumbnail}">
        <meta property="og:url" content="{$VAL_SELF}">
        {/if}
    </head>

And this is the FaceBook open graph tool for checking https://developers.facebook.com/tools/debug/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...