Creating SEO friendly property details URLs
By default a property created in Property Hive, either manually or imported, will have a permalink matching that of the display address:
https://yoursite.com/property/high-street-birmingham
This could be changed however to be more SEO friendly like so it looks like so:
https://yoursite.com/property-for-sale/birmingham/high-street-birmingham
This can be achieved using a snippet like so:
add_filter( 'post_type_link', 'customise_property_post_type_link', 10, 4 );
function customise_property_post_type_link( $post_link, $post, $leavename, $sample )
{
if ( get_post_type($post->ID) == 'property' )
{
$property = new PH_Property($post->ID);
$suffix = 'for-sale';
if ( $property->department == 'residential-lettings' )
{
$suffix = 'to-rent';
}
$area = $property->address_three;
if ( $area == '' )
{
$area = $property->address_four;
}
if ( $area == '' )
{
$area = $property->address_two;
}
if ( $area == '' )
{
$area = 'property';
}
$post_link = str_replace("/property/", "/property-" . $suffix . "/" . sanitize_title($area) . "/", $post_link);
}
return $post_link;
}
add_action( 'init', 'rewrites_init' );
function rewrites_init()
{
add_rewrite_rule(
'property-for-sale/([^/]+)/([^/]+)/?$',
'index.php?post_type=property&name=$matches[2]',
'top' );
add_rewrite_rule(
'property-to-rent/([^/]+)/([^/]+)/?$',
'index.php?post_type=property&name=$matches[2]',
'top' );
}
Once the below code is added to your functions.php file you'll need to visit 'Settings > Permalinks' and just click 'Save changes' to force the rewrite rules to take effect.