2

So I have what seems like a simple problem but can't quite find a solution. On my entry template I'm trying to override the image fields as we're using the imager plugin for transforms. However, it doesn't seem to be working at all. No matter what I put inside the craft.sproutSeo.meta do loop, nothing happens. Even if I hardcode a value in there. It seems simple, but is there something I'm missing here? My code is below:

{% set cardEntryImage = craft.imager.transformImage(entry.blogHeaderImage.first(), { width: 1920, ratio: 16/9 }) %}
{% do craft.sproutSeo.meta({
    ogImage: siteUrl ~ cardEntryImage.getUrl(),
    ogImageSecure: siteUrl ~ cardEntryImage.getUrl(),
    ogImageHeight: cardEntryImage.getHeight(),
    ogImageWidth: cardEntryImage.getWidth(),
    ogImageType: cardEntryImage.getMimeType(),
    twitterImage: siteUrl ~ cardEntryImage.getUrl()
}) %}
  • I'm facing the exact same problem so this is not an answer but more a bump, sorry for that. Based on this page at their docs (link), the method described above should work... But for me it isn't. I've contacted the Sprout support as well, will post back here if I get an answer. – mrsmn Mar 22 '18 at 13:42
2

Could you please let us know where do you output the {% sproutseo 'optimize' %}tag?

The {% do craft.sproutSeo.meta({ tag need to be called before the optimize tag. I'll give you a basic example of how you can do this:

Let's say that you have a _layout where you have the html head tag:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
    {% block head %}
        {% sproutseo 'optimize' %}
        ...
        ...
    {% endblock %}
    ...
</head>

In your section/_entry (extends your layout) When you need to override something with the do craft.sproutSeo.meta you may need to call it before the {% sproutseo 'optimize' %} so you can do something like:

{% extends "_layout" %}
{% set title = entry.title ~ " - Blog" %}

{% block head %}

    {% set cardEntryImage = craft.imager.transformImage(entry.blogHeaderImage.first(), { width: 1920, ratio: 16/9 }) %}
    {% do craft.sproutSeo.meta({
        ogImage: siteUrl ~ cardEntryImage.getUrl(),
        ogImageSecure: siteUrl ~ cardEntryImage.getUrl(),
        ogImageHeight: cardEntryImage.getHeight(),
        ogImageWidth: cardEntryImage.getWidth(),
        ogImageType: cardEntryImage.getMimeType(),
        twitterImage: siteUrl ~ cardEntryImage.getUrl()
    }) %}
    {{ parent() }}

    ...
    ...
{% endblock %}

Best,

-Andre L

| improve this answer | |
  • That works! thanks! I had the call to optimize before doing the overrides, as indicated in the (wrong at the time but now fixed) documentation – mrsmn Mar 28 '18 at 11:17

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.