0

So I've got a fairly complex problem. Allow me to explain...

I've got an EE website where 80% of their traffic comes via social shares of their blog posts, so making sure the Twitter and Facebook meta data is perfect is key. FB and TW require the meta data that shows on a share card be placed within the tag of your website.

There's two different times people share the site

1.) blog posts
2.) global: any other page on the site that's not a blog post

I need the variables/values inside the meta tags, inside to change depending on whether or not the user is sharing a blog post or global page. and IF they are on a blog post, use the EE variables for that specific post.

This is my sloppy attempt at writing what I ultimately need using rough JS syntax:

<head>

if (is blog post) {

{exp:channel:entries channel="blog" limit="1"}

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:site" content="@lorem"/>
<meta name="twitter:title" content="{title}"/>
<meta name="twitter:description" content="{excerpt}"/>
<meta name="twitter:image:src" content="{blog_thumbnail}"/>

{/exp:channel:entries}

} else { 

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:site" content="@lorem"/>
<meta name="twitter:title" content="Lorem ipsum dolor"/>
<meta name="twitter:description" content="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus velit enim, sit amet pulvinar sapien blandit et. In facilisis tortor vitae quam venenatis euismod. Nunc auctor lorem porta mauris congue accumsan."/>
<meta name="twitter:image:src" content="lorem.com/_img/share.jpg"/>

}

</head>

I'm not sure what I should even be using for this? Is there some way to do this IF statement with EE's template code or is there some way to do this on page load with javascript and still get the EE variables?

1
<head>

  <meta name="twitter:card" content="summary_large_image"/>
  <meta name="twitter:site" content="@lorem"/>

  {exp:channel:entries channel="blog" limit="1"}
    {if no_results}
      <meta name="twitter:title" content="Lorem ipsum dolor"/>
      <meta name="twitter:description" content="Lorem ipsum dolor sit amet, consectetur adipiscing elit."/>
      <meta name="twitter:image:src" content="lorem.com/_img/share.jpg"/>
    {/if}
    <meta name="twitter:title" content="{title}"/>
    <meta name="twitter:description" content="{excerpt}"/>
    <meta name="twitter:image:src" content="{blog_thumbnail}"/>
  {/exp:channel:entries}

</head>

Note: Removed the duplicate content out of the tag code so there's no duplication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.