2

I have a pretty specific set up: posts get created via rss feeds and images are not attached to the specific posts, so instead in the entry template I use an image from a related entry. When I try to use the related entry's image as the SEO image and merge it with SEOmatic, it does not merge.

Has anyone ever tried doing this with SEOmatic? This is the code I'm using:

{% if craft.entries.section('episode') %}
   {% set relatedPodcastImage = craft.entries.section('podcastChannel').relatedTo(entry).albumCoverPicture.first().getUrl('large') %}
      {% set seomaticMeta = seomaticMeta | merge(
            { og:
                  {
                  title: entry.title,
          description: entry.podcastDescription,
                  image: relatedPodcastImage
                  }
            },
        { twitter:
                  {
                  title: entry.title,
                  description: entry.podcastDescription,
                  image: relatedPodcastImage
                  }
            }
      ) %}
{% endif %}
2

Make sure you're not doing this inside of a {% block %} or you will run into Twig Processing Order / Scoping issues.

There are some good examples of doing that here: Dynamic Twig SEO Meta

  • Hey Andrew, thanks for the quick response. I'm definitely not inside of the {% block %} tags. I know it's working also because it's correctly merging the entry.title & entry.podcastDescription, but when it comes to the image maybe the page hasn't rendered the related item yet? Which makes it not load in the hook? In the entry template, I'm extending a custom base for this particular entry type: {% extends "base-episodes" %} and in base-episodes I have all the head information including {% hook 'seomaticRender' %} right after my above merge. Any help or insight would be greatly appreciated! – nathanielperales Jan 16 '18 at 9:15
  • With devMode on, what happens if you put this in a {% block %} somewhere: {{ dump(seomaticMeta) }} -- it'll let you see what has actually been set. – andrew.welch Jan 17 '18 at 6:54

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.