Skip Navigation

[Résolu] rendering alternative background image, if it doesn´t exist

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
The user would like to use a background image from a custom field and fallback to a different image when no images are available.

Solution:
This can be done using a conditional block and checking if the image exists. If it does, then use a container that has the background set that image field. Otherwise, use another container that has the background image set to a specific image in the Media library.

This support ticket is created Il y a 3 années et 1 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

Marqué : 

This topic contains 2 réponses, has 2 voix.

Last updated by Mario Il y a 3 années et 1 mois.

Assisted by: Jamal.

Auteur
Publications
#1967821
2021-02-26_11h19_30.png

Set an dynamic background-image in toolset container with Gutenberg. Background image is a toolset custom type "image".
In single template i want to check if the background-image exist and if not, show an autogenerated image.

So i tried to catch the type field rendering with the filter "wpv-post-field-meta-{name}", to check if meta-value is a valid, existing image.
I expect that filter should be fired if i use the shortcode [types field='meetup-pre-image'][/types] for rendering this field.
Unfortunatelly the filter doesn´t fire. Question is why or how could i reach my goal to render an alternative image if background-image not exist?

function cb_prefix_empty_meetup_pre_image( $meta ) {
if ( empty( $meta ) ) {
	die();
		$meta = array( __('No value') );
	}
	return $meta;
}
add_filter( 'wpv-post-field-meta-meetup-pre-image', 'cb_prefix_empty_meetup_pre_image' );
add_filter( 'wpv-post-field-meta-wpcf-meetup-pre-image', 'cb_prefix_empty_meetup_pre_image' );
#1969535

Jamal
Supporter

Languages: Anglais (English ) Français (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

I am not sure if the legacy shortcodes' filters will work on the blocks. I did not test it yet.

What about using a conditional block and checking if the image exists. If it does, then use a container that has the background set that image field. Otherwise, use another container that has the background image set to a specific image in the Media library. Does it make sense?

#1970493

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.