Skip Navigation

[Gelöst] rendering alternative background image, if it doesn´t exist

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 3 Jahren, 9 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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+01:00)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Mario vor 3 Jahren, 9 Monaten.

Assistiert von: Jamal.

Author
Artikel
#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

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!