admin管理员组

文章数量:1323348

Is it possible to make custom URL path for pages ? The current page url is /insight which I need to show like /city/local/insight are any option in wordpress to customise the url ?

Is it possible to make custom URL path for pages ? The current page url is http://localhost.dev/insight which I need to show like http://localhost.dev/city/local/insight are any option in wordpress to customise the url ?

Share Improve this question asked Nov 23, 2016 at 13:53 MuhammedMuhammed 1471 silver badge8 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 2

you can use this plugin to generate this kind of permalink https://wordpress/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' );

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.

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.

本文标签: How to inject custom url path for page