The custom post type method mentioned is likely the superior one, but if you are not comfortable with registering a post type or using that code in a plugin of your own, there is a plugin that the WordPress codex recommends for this: WP Category Permalink.

This is part of the larger entry regarding using permalinks.


For a page, you need to create a parent page(s) with the slug you want to put in between. Then you may choose these pages as a parent to the last slug page (insight page in your case). It will insert the needed slugs into your URL.

So you need to create /city page, then /local page and make /local child to /city page parent. then make /insight page child to /local parent.

Then you may change parent pages visibility to i.e. drafts or private. URL will be preserved.


you can use this plugin to generate this kind of permalink https://wordpress.org/plugins/wp-category-permalink/


It's probably best to register a new post type for this. In custom post types you can easily control the url structure. Use the register_post_type function for this.

In this function you can add a rewrite variable. This variable controls the slug / url structure. Check out this example:

function insight_init() {
  register_post_type( 'insight', array(
      'labels'            => array(),
      'public'            => true,
      'hierarchical'      => false,
      'show_ui'           => true,
      'show_in_nav_menus' => true,
      'supports'          => array( 'title', 'editor' ),
      'has_archive'       => false,
      'rewrite'           => array('slug' => 'city/local')),
      'query_var'         => true,
      'menu_icon'         => 'dashicons-analytics',
  ) );

}
add_action( 'init', 'insight_init' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.