Forum

Thread tagged as: Question

Social meta in Events

Hi,

I am trying to get the social meta og tags into an event (the same as a blog post), so the client can get the fancy links when sharing an event across social media.

To start, I copied the meta_head.html into /templates/events/meta_head.html.

<title><perch:blog id="postTitle" /></title>
    <meta property="og:site_name" content="<perch:setting id="perch_blog_site_name" />" />
    <meta property="og:url" content="<perch:blog id="domain" type="hidden" /><perch:blog id="postURL" type="hidden" />" />
    <meta property="og:title" content="<perch:blog id="og_title" label="Social title" type="text" escape="true" />" />
    <meta property="og:description" content="<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />" /><!--* *-->
    <perch:if exists="og_image">
    <meta property="og:image" content="<perch:blog id="domain" type="hidden" /><perch:blog id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
    </perch:if><!--* *-->
    <perch:if exists="og_type"><!--* *-->
    <meta property="og:type" content="<perch:blog id="og_type" label="Facebook type" type="select" options="article,book,profile,website,video,music" allowempty="true" />" />
    </perch:if><!--* *-->
    <meta property="article:author" content="<perch:blog id="author_facebook" type="hidden" />" />

    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:site" content="<perch:blog id="author_twitter" type="hidden" />" />
    <meta name="twitter:title" content="<perch:blog id="og_title" label="Social title" type="text" escape="true" />" />
    <meta name="twitter:description" content="<perch:blog id="og_description" label="Social description" type="textarea" size="s" escape="true" />" /><!--* *-->
    <perch:if exists="og_image">
    <meta property="twitter:image" content="<perch:blog id="domain" type="hidden" /><perch:blog id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
    </perch:if><!--* *-->
    <meta name="twitter:url" content="<perch:blog id="domain" type="hidden" /><perch:blog id="postURL" type="hidden" />" />

Now in /templates/layouts/global/head.php, I inserted,

<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <?php
    if(perch_layout_has('event'))
    {
      perch_events_custom([
      'filter'   => 'eventSlug',
      'match'    => 'eq',
      'value'    => perch_get('s'),
      'template' => 'events/meta_head.html'
      ]);
    }
    else
    {
    if(perch_layout_has('blog-post'))
    {
      perch_blog_post_meta(perch_get('s'));
    }
    else
    {
    if(perch_layout_has('title'))
    {
      $title = perch_layout_var('title', true);
    }
    else
    {
      $title = perch_pages_title(true);
    }

      echo '<title>' . $title . '</title>';
      perch_page_attributes([
        'template' => 'seo.html'
      ]);
    }
  ?>
...

Finally in /templates/pages/events/event.php, I've added,

<?php
// Site global head content + page title
perch_layout('global/head', ['event'=>true,]);
// Site global header
perch_layout('global/header');
?>

However this isn't achieving the desired results?

Could I get some advise please

Grant Smith

Grant Smith 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hi Grant,

You need to edit the template:

  • perch:blog to perch:events
  • postTitle to eventTitle
  • postURL to eventURL

and so on..

Thanks for that! What a mistake to make! I think this is now corrected, but I'm still not seeing the social tab on the event in the admin area?

Now corrected and my /templates/events/meta_head.html now looks like this;

<title><perch:events id="eventTitle" /></title>
    <meta property="og:site_name" content="<perch:setting id="perch_blog_site_name" />" />
    <meta property="og:url" content="<perch:events id="domain" type="hidden" /><perch:events id="eventURL" type="hidden" />" />
    <meta property="og:title" content="<perch:events id="og_title" label="Social title" type="text" escape="true" />" />
    <meta property="og:description" content="<perch:events id="og_description" label="Social description" type="textarea" size="s" escape="true" />" />
    <perch:if exists="og_image">
    <meta property="og:image" content="<perch:events id="domain" type="hidden" /><perch:events id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
    </perch:if>
    <perch:if exists="og_type">
    <meta property="og:type" content="<perch:events id="og_type" label="Facebook type" type="select" options="article,book,profile,website,video,music" allowempty="true" />" />
    </perch:if>
    <meta property="article:author" content="<perch:events id="author_facebook" type="hidden" />" />
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:site" content="<perch:events id="author_twitter" type="hidden" />" />
    <meta name="twitter:title" content="<perch:events id="og_title" label="Social title" type="text" escape="true" />" />
    <meta name="twitter:description" content="<perch:events id="og_description" label="Social description" type="textarea" size="s" escape="true" />" />
    <perch:if exists="og_image">
    <meta property="twitter:image" content="<perch:events id="domain" type="hidden" /><perch:events id="og_image" label="Image when shared" help="Should be at least 1200x630" type="image" width="1200" />" />
    </perch:if>
    <meta name="twitter:url" content="<perch:events id="domain" type="hidden" /><perch:events id="eventURL" type="hidden" />" />

Hi,

Sorry for bumping this post, but I still haven't managed to get this working. Any help would be appreciated.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hi Grant,

Adding the meta_head.html template won't add a social tab like the Blog app. The tab is there by default on the Blog app.

You can still use this template to output the necessary tags to the page's <head>.

If any of the fields on this template needs to be editable, you need to add the fields to your event.html too.

Thanks Hussein, all sorted