epl_property_gallery_html: supply your own listing gallery
Description #
Replaces the image gallery on a single listing with your own HTML. Return a string and EPL shows it instead of its gallery of attached images. Return null (the default) and EPL shows its normal gallery.
Use it when the listing images aren't in the WordPress media library, for example images hosted on a CDN by an import add-on, or to swap in a slider of your own.
It runs where EPL shows the gallery:
- The
epl_property_galleryaction in the single listing template (and the Elementor Gallery widget, which runs the same action). This only runs when Easy Property Listings > Settings > Listing Single View > Automatically display image gallery? is enabled. - The EPL - Listing Gallery widget. Your HTML goes inside the widget wrapper and below the widget title.
Usage #
add_filter( 'epl_property_gallery_html', 'my_property_gallery_html', 10, 2 );
Parameters #
$html (string|null)
The gallery HTML. Default null, which means "use EPL's gallery". Return a string to replace it. An empty string '' shows no gallery at all.
$post_id (int)
The listing's post ID.
EPL prints your string as it is, without escaping, so escape every URL and value you put in it.
Examples #
Build the gallery from a custom field that holds an array of image URLs. Listings without that field keep EPL's gallery.
function my_property_gallery_html( $html, $post_id ) {
$urls = get_post_meta( $post_id, 'my_cdn_images', true ); // An array of image URLs.
if ( empty( $urls ) || ! is_array( $urls ) ) {
return $html; // null: EPL shows its normal gallery.
}
$out = '<div class="epl-gallery property-gallery my-cdn-gallery">';
foreach ( $urls as $url ) {
$out .= '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $url ) . '" alt="" loading="lazy"></a>';
}
$out .= '</div>';
return $out;
}
add_filter( 'epl_property_gallery_html', 'my_property_gallery_html', 10, 2 );
Related #
- epl_property_gallery_shortcode: change the columns or size of EPL's own gallery instead of replacing it.
Source #
lib/includes/template-functions.php, in epl_property_gallery(), and lib/widgets/class-epl-widget-property-gallery.php, in EPL_Widget_Property_Gallery::widget(). Since 3.6.