Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image fallback #66

Closed
Moorst opened this issue Feb 22, 2018 · 1 comment
Closed

Image fallback #66

Moorst opened this issue Feb 22, 2018 · 1 comment

Comments

@Moorst
Copy link

Moorst commented Feb 22, 2018

Is it possible to have fallback images, similar to how we can define fallbacks for titles & descriptions using the seo.custom object?

e.g.
{% set seo = craft.seo.custom(entry.seo.title, entry.seo.description ?: entry.introduction, true) %}

Also, setting seo to the seo.custom object as above stops pulling through any social data.

@Tam Tam added the enhancement label Mar 1, 2018
@Tam Tam closed this as completed in 4c763af Mar 2, 2018
@Moorst
Copy link
Author

Moorst commented Mar 5, 2018

Thanks!

Dropping my code in here for anyone else who wants to use this in the same way.

{% set seo = entry.seo %}
{% set social = craft.seo.social(seo) %}
{% set fb = social.facebook -%}
{% set tw = social.twitter -%}

{% set seo = craft.seo.custom(
	entry.seo.title, 
	entry.seo.description ?: entry.introduction|striptags|raw, 
	false,
	{
		twitter: { image: tw.image ?: entry.image.first() },
		facebook: { image: fb.image ?: entry.image.first() },
	}
) %}

This will use the entry.image field by default and will override if an image is defined in the social tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants