Dedicated Banner upload field for the Vantage

This mod is for Vantage users who want to use a special custom field for the listing page banner upload.

Time needed: 5 minutes.

By default, the Vantage theme uses the first available image for the listing thumbnail and the page banner. This might not be convenient. Especially when users use logo images in thumbnails, which appears on the banner.

This is definitely a UX issue and it will be fixed in the next versions of the Vantage theme. In this article, we’ll show you how to fix it with a small code snippet before the official release.

  1. Create new File Upload field

    Open Vantage → Forms and create new File Upload field with name Banner Image. Set “Image” for Allowed Extensions parameter. File limit 1, embed limit 0. The name of the field in example app_banner-image.Custom banner upload field

  2. Add PHP code snippet

    You can use Code Snippets plugin for adding following PHP code on your site. For reference read our instruction Easy way to add custom PHP code on your WordPress site.

function arthemes_va_cover_image( $image, $args ) {

	if ( is_singular( VA_LISTING_PTYPE ) && 'full' === $args['size'] ) {
		$banner_image = get_post_meta( get_the_ID(), 'app_banner-image', true );
		if ( ! empty( $banner_image[0] ) ) {
			$image= wp_get_attachment_image_src( $banner_image[0], $args[ 'size' ] );
		}
	}

	return $image;
}
add_filter( 'va_cover_image', 'arthemes_va_cover_image',10, 2 );

function arthemes_exclude_banner_from_the_gallery( $wp_query ) {
	if ( 'attachment' === $wp_query->get( 'post_type' ) && get_the_ID() === $wp_query->get( 'post_parent' ) && is_singular( VA_LISTING_PTYPE ) ) {
		$featured_id = get_post_thumbnail_id( get_the_ID() );
		if (  $wp_query->get( 'post__not_in' ) === array( $featured_id ) ) {
			$banner_id = get_post_meta( get_the_ID(), 'app_banner-image', true );
			$wp_query->set( 'post__not_in', array_merge( array( $featured_id ), (array) $banner_id ) );
		}
	}
}
add_filter( 'pre_get_posts', 'arthemes_exclude_banner_from_the_gallery' );

Now, your users will use Banner Image field for uploading banners without hassle.

Banner upload on the listing form
Banner upload on the listing form.

In result a single listing page look much more better.

Banner image on the listing page
Banner image on the listing page.