0
votes

In WordPress you can change the Custom Post Type slug easily from the dashboard post shown in the image below, but how can I change it via the back-end for all my CPT's?

enter image description here

I know I can use the rewrite argument, but that seems to only change the custom post type title.

How can I code a function to change to this:

  • sitename/projects/project

instead of

  • sitename/projects/slug-of-post
2

2 Answers

0
votes

I'd suggest taking a look at the following plugin https://wordpress.org/plugins/permalinks-customizer/ .

It has worked for me, and if would like to write your own functions instead of using a plugin, you could take a look at how the plugin's authors do it.

Thanks!

0
votes

Do I get it right, that you want to change the permalink base?

Custom Post Types are registered through:
https://developer.wordpress.org/reference/functions/register_post_type/
register_post_type

This function has the rewrite parameter. The sub parameter slug might be what you are searching for.

You can alter the parameters of registered post types with the filter register_post_type_args see here for more information about it:
https://wordpress.stackexchange.com/a/230313/179522

Don't forget to flush your permalink rules after doing changes. Here is how: https://wpastra.com/docs/how-to-refresh-wordpress-permalinks/