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:

2 Likes

Hello, I have tried adding this code but the map is still being displayed, can you please confirm?

Could you please clarify where the map is still being displayed? For instance:

  • Is it on the listing page, the listings page, or the vendor page?

Additionally, it would be great if you could:

  1. Share a screenshot of the code you pasted into your functions.php file.
  2. Provide a screenshot of the page where the map is still visible.

This will help me identify the issue and guide you better.

1 Like

Thank you so much and +1 for explaining where to paste the code. Earlier was putting the code at the wrong place. It worked!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.