Change default url to plugin custom post type

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

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

http://localhost:81/luckydraw/index.php/voucher/testing-2/

But I want to change it to:

http://localhost:81/luckydraw/voucher/testing-2/

How would I do this?

Topic plugins-url url-rewriting plugin-development plugins Wordpress

Category Web


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

Manually

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:

Plugin

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

Download Link: Custom Post Type Permalinks


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.


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.

About

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