Skip to content

Auto add the necessary meta tags for Facebook Open Graph and Twitter Cards

Notifications You must be signed in to change notification settings

marc524/bos.insert_social_meta.ee_addon

Repository files navigation

BOS Insert Social Meta

The BOS Insert Social Meta will insert the necessary Facebook Open Graph meta-data and
Twitter Cards meta-data only when the link is coming from those social sites.

Default Usage:

Put the following tag inbetween your <head></head> tags of your template. My preferred way of doing this is to assign this tag as a Stash variable that’s down in between your channels entry tags. Then pull that Stash variable up to your head content.

 {exp:bos_insert_social_meta title="{title}" description="" image="" admins="123456789,987654321"}
  • title is Required.

Default Options that can be changed:

  • site: Default to the Site Name in your config file.
  • url: Defaults to the current page URL.
  • viewable: yes|no – if you want to see the meta tags in your source code, set to YES. Defaults to NO and the meta tags will only be seen by the social bots.

Options that default to blank

  • description: Custom description field
  • descchars: You can pass in a larger string and it will truncate to this number of characters. Defaults to 300.
  • admins: Facebook admin ID numbers
  • twitter: Twitter handle (leave off @ symbol)
  • image: image to share
  • width: width of image

SEO Lite Support

  • seolite: yes|no – if you are using the SEO Lite Plugin and want to pull the custom description that can be set per entry, set this to yes
  • entryid: you need to pass in the entry_id to lookup the entry in the SEO Lite table.

All Paramaters Example:

 {exp:bos_insert_social_meta site="{site_name}" title="{title}" description="{body}" descchars="300" image="{image}" width="300" admins="123456789,987654321" twitter="ellislab" seolite="yes" entryid="{entry_id}" viewable="yes"}

Test/Debug:

Facebook Test/Debug
Visit: https://developers.facebook.com/tools/debug/

Twitter Test/Debug
Visit: https://cards-dev.twitter.com/validator

Example with Stash

Here is an example on using Stash embeds for Template Partials and how I use this plugin in this case.

Page Template


  {embed="_layouts/_main"}
  {exp:channel:entries channel="channel" limit="1" dynamic="yes"}
    {exp:stash:set parse_tags="yes"}
      {stash:pagetitle}{title} | {/stash:pagetitle}
      {stash:socialtags}{exp:bos_insert_social_meta title="{title}" description="{body}" image="{image}"  twitter="ellislab"}{/stash:socialtags}
      {stash:content}
        <div class="page">
          <h1>{title}</h1>
          <div class="image-class">{image}</div>
          <div class="article">{body}</div>
        </div>
      {/stash:content}
    {/exp:stash:set}
  {/exp:channel:entries}

Main Layout Template


  <!DOCTYPE html>
  <head>
    <title>{exp:stash:get name="pagetitle"}{site_name}</title>
    {exp:stash:get name="socialtags"}
  </head>
  <body>
    {exp:stash:get name="content"}
  </body>
  </html>

About

Auto add the necessary meta tags for Facebook Open Graph and Twitter Cards

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published