I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.
I set my home page to be a single custom post type in settings->reading->static page so the url was like this:
But now it's:
How can i change it so the home page is just the single custom post type without the "/destination/london" part?
Edit:
After adding this code it almost work:
function enable_front_page_destination( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );
But now the home url is / and it should be
Thank you.
I've changed the permalinks to add a string at the beginning of the url like this: /london/%postname%/ This works perfect for all the pages but not for my home page.
I set my home page to be a single custom post type in settings->reading->static page so the url was like this: http://example/destination/london
But now it's: http://example/london/destination/london
How can i change it so the home page is just the single custom post type without the "/destination/london" part?
Edit:
After adding this code it almost work:
function enable_front_page_destination( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'destination' );
}
add_action( 'pre_get_posts', 'enable_front_page_destination' );
But now the home url is http://example/ and it should be http://example/london
Thank you.
EDIT Since, as you mentioned it in comments, it can have several values, maybe we could retrieve the city list and set corresponding rewrite rules like so?
assuming $city_list is an array of cities
foreach ($city_list as $city) {
add_rewrite_rule('/^'. $city .'/destination/'. $city .'$/','index.php?p=idofyourhomepage','top');
}
How about trying some rewrite rules.
add_rewrite_rule('/^london/destination/london$/','index.php?p=idofyourhomepage','top');
Or
add_rewrite_rule('/^london/destination/london$/','index.php?pagename=nameofyourhomepage','top');
Go validate your permalink settings to refresh the rules.