2

I'm currently using SEO by EtherCreative on Craft 2, one of my pages needs a custom title and description injected into it like this on the docs:

In some cases, you will not have access to an SEO field, but will want to set the page title & description. You can do this by creating a custom SEO object using the function below:

craft.seo.custom('The Page Title', 'The page description', $includeDefaultTitleSuffix)

Mine seems to be throwing errors or not doing anything like so:

  {% set seo = craft.seo.custom('Discount codes and vouchers for {{ query }}', 'You searched for {{ query }}. Check out the latest live {{ query }} discount codes & voucher codes for {{ "now"|date("m") }} {{ "now"|date("Y") }} only at Vouchertoday.uk') %}
  • 1
    Maybe you could explain the problem a little bit better? What doesn't work? What errors do you receive? – Robin Schambach Feb 17 '18 at 13:19
1

You can't automatically expand variables inside strings in Twig as you would normally do in PHP.

Instead, you have to concatenate your strings.

{% set seo = craft.seo.custom('Discount codes and vouchers for ' ~ query, 'You searched for ' ~ query ~ '. Check out the latest live ' ~ query ~ ' discount codes & voucher codes for ' ~ now|date('m') ~ ' ' ~ now|date('Y') ~ ' only at Vouchertoday.uk') %}
  • Thanks for the answer, but it seems to still not be setting the object? – JMKelley Feb 28 '18 at 16:43
  • Try {% do craft.seo.custom(all the stuffs) %} instead of setting it to a local variable. NB: I haven't used this exact plugin myself, so I'm just trying to apply logic to it :) – Fuglsetrampen Mar 1 '18 at 14:18
  • This throws an error. – JMKelley Mar 4 '18 at 12:14
  • "Unexpected token "operator" of value "=" ("end of statement block" expected)." – JMKelley Mar 4 '18 at 12:14
  • Hmm, could you post the entire line? There's no '=' in my example, so I need to see where else it could be going wrong – Fuglsetrampen Mar 5 '18 at 7:53

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.