Skip to content

Instantly share code, notes, and snippets.

@kprajapatii
Created January 24, 2017 05:25
Show Gist options
  • Save kprajapatii/63f78161f23e067291132a2638af7aec to your computer and use it in GitHub Desktop.
Save kprajapatii/63f78161f23e067291132a2638af7aec to your computer and use it in GitHub Desktop.
// Hide "Location", "Country", "Region", "City" for location neighbourhood breadcrumb
// Hide "Location", "Country", "Region", "City" for location neighbourhood breadcrumb
function gd_location_neighbourhood_breadcrumb( $breadcrumb, $separator, $echo = false ) {
if ( geodir_is_page( 'location' ) ) {
$location_link = geodir_get_location_link('base');
$location_prefix = get_option('geodir_location_prefix');
$breadcrumb = '<div class="geodir-breadcrumb clearfix"><ul id="breadcrumbs">';
$breadcrumb .= '<li><a href="' . home_url() .'">' . __( 'Home', 'geodirlocation' ) . '</a></li><li>';
$locations = geodir_get_current_location_terms();
$hide_url_part = array( 'gd_country', 'gd_region', 'gd_city' );
foreach ( $locations as $key => $location ) {
if ( in_array( $key, $hide_url_part ) ) {
continue;
}
if ( get_option('permalink_structure') != '' ) {
$location_link .= $location;
} else {
$location_link .= '&' . $key . '=' . $location;
}
$location_link = geodir_location_permalink_url( $location_link );
$location = urldecode( $location );
$location_title = '';
if ( $key == 'gd_country' && $location_actual = get_actual_location_name( 'country', $location ) ) {
$location_title = get_actual_location_name( 'country', $location, true );
} else if ( $key == 'gd_region' && $location_actual = get_actual_location_name( 'region', $location ) ) {
$location_title = get_actual_location_name( 'region', $location, true );
} else if ( $key == 'gd_city' && $location_actual = get_actual_location_name( 'city', $location ) ) {
$location_title = get_actual_location_name( 'city', $location, true );
} else if ( $key == 'gd_neighbourhood' && $location_actual = get_actual_location_name( 'neighbourhood', $location ) ) {
$location_title = get_actual_location_name( 'neighbourhood', $location, true );
}
if ( $location_title == '' ) {
$location_title = preg_replace( '/-(\d+)$/', '', $location );
$location_title = preg_replace( '/[_-]/', ' ', $location_title );
$location_title = __( $location_title, 'geodirectory' );
}
if ( $location != end($locations ) ) {
$breadcrumb .= $separator . '<a href="' . $location_link . '">' . $location_title . '</a>';
} else {
$breadcrumb .= $separator . $location_title ;
}
}
$breadcrumb .= '</li></ul></div>';
}
if ( $echo ) {
echo $breadcrumb;
} else {
return $breadcrumb;
}
}
add_filter( 'geodir_breadcrumb', 'gd_location_neighbourhood_breadcrumb', 100, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment