Join the Voxel Guide Community!

Get Involved

Voxel Theme Version: 1.5.4 | Elementor Plugin Version: 3.28.0

You are now eligible to list your profile publicly!

Hide the Container which have the related places or posts if there is no posts in the vx postfeed widget

Description/Instructions

This snippet hides the container which has the vx postfeed widget if there are no related posts displayed.

Instructions

You can use free elementor html widget to use this snippet. Don't forget to add "related-places" css class to the container which have the postfeed widget. You can change the css class as you need but don't forget to change it in the js code snippet.

<script>
document.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {
// Find the container with the "related-places" class
const relatedPlacesContainer = document.querySelector('.related-places');

if (relatedPlacesContainer) {
// Find the post feed widget inside the container
const postFeedWidget = relatedPlacesContainer.querySelector('.elementor-widget-ts-post-feed');

if (postFeedWidget) {
// Check if the post feed grid is empty (has no child elements besides the no-results message)
const feedGrid = postFeedWidget.querySelector('.post-feed-grid');
const noResultsElement = postFeedWidget.querySelector('.ts-no-posts');

// Check if the feed is truly empty - both conditions must be true:
// 1. The no-results element must exist
// 2. The feed grid must have no direct children OR only have the no-results class
if (noResultsElement &&
(feedGrid.children.length === 0 ||
(feedGrid.classList.contains('post-feed-no-results') && !feedGrid.querySelector(':scope > *')))) {
// Hide the entire container
relatedPlacesContainer.style.display = 'none';
}
}
}
}, 700); // Increased delay to ensure content is fully loaded
});
</script>

  • JS
Copy Code

Let's Chat About this Snippet

Chat Toggle
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Ask me anything about Voxel!
Send
Powered by AI24