Skip to content

Instantly share code, notes, and snippets.

@hbaker
Last active October 12, 2023 15:19
Show Gist options
  • Save hbaker/edd05135ea9089f09c1983901df5e405 to your computer and use it in GitHub Desktop.
Save hbaker/edd05135ea9089f09c1983901df5e405 to your computer and use it in GitHub Desktop.
Divi Theme - Rename Divi's 'Projects' Custom Post Type
// RENAME DIVI PROJECTS CUSTOM POST TYPE
function ze_rename_projects_cpt() {
register_post_type( 'project',
array(
'labels' => array(
'name' => __( 'Specials', 'divi' ), // CHANGE SPECIALS TO WHATEVER YOU WANT
'singular_name' => __( 'Special', 'divi' ), // CHANGE SPECIAL TO WHATEVER YOU WANT
),
'has_archive' => true,
'hierarchical' => true,
'public' => true,
'rewrite' => array( 'slug' => 'special', 'with_front' => false ), // CHANGE SPECIAL TO WHAT YOU WANT YOUR SLUG TO BE
'menu_icon' => 'dashicons-tag', // CHANGE TO AN ICON TO MATCH YOUR NEW POST TYPE
'supports' => array(),
));
}
add_action( 'init', 'ze_rename_projects_cpt' );
// END RENAME DIVI PROJECTS CUSTOM POST TYPE
@hbaker
Copy link
Author

hbaker commented Nov 29, 2017

How to Rename Divi's Default 'Projects' Custom Post Type

Divi assumes you want a custom post type named 'Projects'. Follow these steps if you would like to rename this default post type.

  1. Add the code above to the bottom of your functions.php file
  2. Change the plural 'Specials' to whatever you want your new custom post type to be
  3. Change the singular 'Special' to the singular version of your new custom post type
  4. Change the 'special' slug to whatever you want your new URLs to be
  5. Change the 'dashicons-tag' menu icon to something that matches your new custom post type. You can find some options for other menu icons here. Be sure to click on the icon you want to use and copy the hyphenated name that starts with dashicons-

@Doebank
Copy link

Doebank commented Aug 19, 2021

Thanks for this! It's perfect. I especially appreciate the fact that you included the bit to change the admin icon. :)

@Silnoreki
Copy link

Code did the job perfectly. Thanks for share!

@drwphi
Copy link

drwphi commented Nov 10, 2022

Works great after I saved the permalinks again!

@tobijafischer
Copy link

Thanks a lot, that worked like a charm. To still be able to access it through the Wordpress REST Api, I had to add additional arguments:

'show_in_rest' => true,
rest_base' => 'customslug',

This way the posts will be returned to the following endpoint: /wp-json/wp/v2/customslug

@SpaniWeb
Copy link

SpaniWeb commented Aug 9, 2023

Super efficient for those who work with DiVi,
Thank you very much for your contribution!

@synapsian-norton
Copy link

A better way would be to use the filter register_post_type_args. Something like this:

function projects_to_teams($args, $post_type)
{
	if ($post_type == 'project') {
		$args['rewrite']['slug'] = 'team';
		$args['menu_icon'] = 'dashicons-groups';
		$args['labels'] = array(
			'name' => _x('Team Members', 'Post Type General Name', 'textdomain'),
			'singular_name' => _x('Team Member', 'Post Type Singular Name', 'textdomain'),
		);
	}
	return $args;
}
add_filter('register_post_type_args', 'projects_to_teams', 10, 2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment