Jump to content

Knowledgebase Social Sharing


Recommended Posts

This will add the meta data for sharing Knowledgebase articles on Facebook and Twitter.

 

It gets the article title, description and it selects the first image from the article if any to show on your social share post.

 

I have separate meta data sections for different pages, this is just the knowledgebase section.

 

Change the "yourdata" accordingly. Adjust as needed.

 

 <title>{if $catname}{$catname}{/if} - {if $kbarticle.title}{$kbarticle.title} - {/if}{$pagetitle} - {$companyname}</title>
   <meta name="description" content="{$kbarticle.text|truncate:150|strip_tags}">

{if preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i',$kbarticle.text, $result)}

<meta property="og:image"
content="{$result[1]}" />
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="{$result[1]}">
{/if}
<meta property="og:title" content="{if $catname}{$catname} -{/if} {if $kbarticle.title}{$kbarticle.title} - {/if}{$pagetitle} - {$companyname}" />
<meta property="og:site_name" content="yourdata"/>
<meta property="og:url" content="http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" />
<meta property="og:description" content="{$kbarticle.text|truncate:150|strip_tags:false}" />
<meta property="fb:app_id" content="yourdata" />


<meta name="twitter:site" content="@yourdata">
<meta name="twitter:creator" content="@yourdata">
<meta name="twitter:title" content="{if $catname}{$catname} -{/if} {if $kbarticle.title}{$kbarticle.title} - {/if}{$pagetitle} - {$companyname}">
<meta name="twitter:description" content="{$kbarticle.text|truncate:150|strip_tags:false}">

Link to comment
Share on other sites

  • 3 years later...

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...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated