How to Remove Map from Listing Page?

Many people have already discussed this and found solutions using CSS to hide the map from the listing page. But let’s be real, what’s the point of just hiding it? The map isn’t entirely free like other elements in HivePress. If you get a lot of visitors, you’ll eventually have to pay for map API usage. Even if you hide the map with CSS, the API calls still happen in the background, costing you money.

So, I searched the HivePress community for a proper solution and found a code snippet on HivePress Gist:

add_filter(
	'hivepress/v1/templates/listing_view_page',
	function( $template ) {
		hivepress()->template->fetch_block( $template, 'location_container' );
		return $template;
	},
	1000
);

Unfortunately, this didn’t work for me, even after testing with both Google Maps and Mapbox. :smirk:

Solution:
With guidance from HivePress team members @andrii and @ihor - I wrote this code:

add_filter(
	'hivepress/v1/templates/listing_view_page',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'listing_map' => [
						'type' => 'content',
					],
				],
			]
		);
	},
	1000
);

This snippet does two important things:

  1. Removes the map view from the listing page.
  2. Removes the data-component="map" attribute.

According to the HivePress team, if your page doesn’t include data-component="map", all map API calls are stopped. This helps reduce map loading costs by removing the map view from the listing page if it’s not needed.

Conclusion:
If you want to remove the map from the listing page and stop the API calls completely, this code is the way to go. Try it out and save some money on unnecessary map loading! :rocket:

1 Like