Overriding listing-location.php

Trying to override listing-location.php in my child theme but it doesn’t do it even folder structure is kept. The code works when amending original file. Trying to shorten the displayed address with this code:

<?php
/**
 * Listing location template.
 *
 * This template can be overridden by copying it to yourtheme/hivepress-geolocation/templates/listing/view/listing-location.php.
 *
 * @param HivePress\Models\Listing $listing Listing instance.
 */
defined( 'ABSPATH' ) || exit;

if ( $listing->get_location() ) :
    $location = $listing->get_location();
    $location_parts = explode( ',', $location );
    if ( count( $location_parts ) >= 3 ) {
        $city = trim( $location_parts[0] );
        $district = trim( $location_parts[1] );
        $location = $city . ', ' . $district;
    }
    ?>
    <div class="hp-listing__location">
        <i class="hp-icon fas fa-map-marker-alt"></i>
        <?php if ( get_option( 'hp_geolocation_hide_address' ) ) : ?>
            <span><?php echo esc_html( $location ); ?></span>
        <?php else : ?>
            <a href="<?php echo esc_url( hivepress()->router->get_url( 'location_view_page', [ 'latitude' => $listing->get_latitude(), 'longitude' => $listing->get_longitude() ] ) ); ?>" target="_blank"><?php echo esc_html( $location ); ?></a>
        <?php endif; ?>
    </div>
<?php endif; ?>

Please ensure that file in your child theme has this path: /themes/your-child-theme/hivepress/listing/view/listing-location.php

We have tested your code snippet locally, and it seems okay. Please try to add the text, for example, “Hello World” to your code snippet, for example, after tag div to test if your file changes the default listing-location file

Thanks! it worked! I created a folder of “hivepress-geolocation” instead of “hivepress”

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