Hi!
Listings meta data is filterable to turn text into clickable links, but by default the [property_details]
shortcode escapes HTML, so your clickable link would appear as <a href="https://example.com" rel="nofollow">https://example.com</a>
instead of https://example.com.
To work around this, you could write your own [custom_property_details]
shortcode that prevents HTML from being escaped. You could do it like this:
1. Take a full backup of your site.
2. Add the following code to your active theme’s functions.php file:
//* Make listing_url post meta value a clickable link
add_filter( 'get_post_metadata', 'sp_filter_listing_link', 10, 4 );
function sp_filter_listing_link( $meta_value, $object_id, $meta_key, $single ) {
if ( is_admin() || ! isset( $meta_key ) || '_listing_url' != $meta_key ) {
return null;
}
$meta_cache = wp_cache_get($object_id, 'post_meta');
if ( !$meta_cache ) {
$meta_cache = update_meta_cache( 'post', array( $object_id ) );
$meta_cache = $meta_cache[$object_id];
}
if ( isset($meta_cache[$meta_key]) ) {
$value = maybe_unserialize( $meta_cache[$meta_key][0] );
return make_clickable( $value );
}
}
//* Add a [custom_property_details] shortcode to prevent HTML links from being escaped
add_shortcode( 'custom_property_details', 'custom_property_details_shortcode' );
function custom_property_details_shortcode( $atts ) {
global $post;
$property_details = apply_filters( 'agentpress_property_details', array(
'col1' => array(
__( 'Price:', 'agentpress-listings' ) => '_listing_price',
__( 'Address:', 'agentpress-listings' ) => '_listing_address',
__( 'City:', 'agentpress-listings' ) => '_listing_city',
__( 'State:', 'agentpress-listings' ) => '_listing_state',
__( 'ZIP:', 'agentpress-listings' ) => '_listing_zip'
),
'col2' => array(
__( 'MLS #:', 'agentpress-listings' ) => '_listing_mls',
__( 'Square Feet:', 'agentpress-listings' ) => '_listing_sqft',
__( 'Bedrooms:', 'agentpress-listings' ) => '_listing_bedrooms',
__( 'Bathrooms:', 'agentpress-listings' ) => '_listing_bathrooms',
__( 'Basement:', 'agentpress-listings' ) => '_listing_basement'
)
) );
$output = '';
$output .= '<div class="property-details">';
$output .= '<div class="property-details-col1 one-half first">';
foreach ( (array) $property_details['col1'] as $label => $key ) {
$output .= sprintf( '<b>%s</b> %s<br />', esc_html( $label ), get_post_meta( $post->ID, $key, true ) );
}
$output .= '</div><div class="property-details-col2 one-half">';
foreach ( (array) $property_details['col2'] as $label => $key ) {
$output .= sprintf( '<b>%s</b> %s<br />', esc_html( $label ), get_post_meta( $post->ID, $key, true ) );
}
$output .= '</div><div class="clear">';
$output .= sprintf( '<p><b>%s</b><br /> %s</p></div>', __( 'Additional Features:', 'agentpress-listings' ), get_the_term_list( $post->ID, 'features', '', ', ', '' ) );
$output .= '</div>';
return $output;
}
3. Replace the [property_details]
shortcode in your listing with [custom_property_details]
.
You should then find that URLs you enter into your custom _listing_url
field become clickable links on the front end.