I have a custom post type in my plugin "Luckydraw" as 'voucher'.

By clicking on post link, wordpress generates its URL as :


But I want to change it to:


How would I do this?

  • Is your installation inside a subdirectory named luckydraw? What is the root of your WordPress installation? – Tom J Nowell May 21 '16 at 22:56
  • Yes it is inside the luckydraw menu. That is luckydraw plugin menu. – Mrudang Shah May 23 '16 at 4:57
  • So just to be clear your WordPress installation is located at localhost:81/luckydraw? I know not of any menus. When I mean root, I mean the frontpage of the WP installation, ignoring anything else hosted on your server, aka you have a folder called luckydraw containing a WP install, that you've an admin folder at localhost:81/luckydraw/wp-admin, etc, can you confirm? – Tom J Nowell May 23 '16 at 10:39
  • Yes exactly. ... luckydraw is my plugin name so my folder hirarchy is look like this C:\xampp\htdocs\luckydraw\wp-content\plugins\lucky-draw – Mrudang Shah May 23 '16 at 10:48
  • Thanks that clears up a lot of confusion, most of the answers below are working on the premise that you've installed WordPress at localhost:81/ not in the subfolder luckydraw, your wording implies that your plugin adds a luckydraw rewrite rule, which is not accurate – Tom J Nowell May 23 '16 at 11:00

I am not sure I follow your question, title seems different from question itself.

You seem to want to get rid of index.php in URL?

It's hard to say confidently from outside, but it looks like PATHINFO permalink.

If that's the case you would need to change your WP permalink configuration to more common "pretty" one. Doesn't have anything to do with CPT's config.

  • I believe this is the correct answer, but it would be clearer if it showed a screenshot of the permalinks page with the option selected – Tom J Nowell May 23 '16 at 11:01

You can achieve your task in both ways through plugin as well as coding


Please see the documentation on URLs of Namespaced Custom Post Types Identifiers. One of the options available to you is to add a 'rewrite' argument to register_post_type(). From the docs:


Custom Post Type Permalinks allow you edit the permalink structure of custom post type.

Download Link: Custom Post Type Permalinks


Change or add the 'rewrite' => array( 'slug' => 'luckydraw', 'with_front' => false ), into the register_post_type arguments, This will change the slug of your custom post type.

  • Dear firend, thank you for the reply, but this is not the case. – Mrudang Shah May 23 '16 at 5:12
  • Than can you please explain in brief so i can help you thanks – Mukesh Ram May 23 '16 at 5:16
  • Yes, when we create a post then WP automatically generates a slug; in my case it generates a slug like- localhost:81/luckydraw/index.php/voucher/testing-2 ; But i need to change it to :- localhost:81/luckydraw/voucher/testing-2 ; in other way i can say i have to run plugin file by default not theme file that's idex.php – Mrudang Shah May 23 '16 at 5:20
  • Ok, now first of all change the permalink to post name and add the default wordpress .htaccess file this will remove index.php and you will get your desired slug, thanks – Mukesh Ram May 23 '16 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.