How to Rename Projects Tab on the Divi Website

by Apr 25, 2020Tutorials

Often enough, when we stroll through the Divi Facebook groups, we see the same questions over and over again. That’s why we decided to start a new tutorials series where we talk about those questions and how to solve them.

Today’s topic is “How can you rename the Projects post type from Divi”. It seems to be such a common issue, that we even integrated a solution right into Divi Pixel. That’s why this tutorial has two parts:

  1. How to solve the issue with Divi Pixel
  2. How to solve the issue using some fairly simple code
How to rename Divis “Project” post type using Divi Pixel?

Well, nothing easier than that. Simply head over to the Divi Pixel options panel and scroll down to Rename Projects Custom Post Type. Activate the option and enter the labels for Singular Name and Plural Name. Finally, if you want the entries to be available under a different slug, enter the slug of your choice in the Slug field. This will change the URL from example.com/project/some-project to example.com/slug/some-project. Save the options, reload your page and you’re good to go.

In some rare cases, you might need to re-save your permalink structure to get the changes applied to existing projects. To do this, head over to Settings → Permalinks and simply click the Save Changes button

How to rename Divis “Projects” post type using PHP

As a non-programmer, this might be a bit intimidating at first, but it actually isn’t that hard to do. WordPress is all about extensibility, so there are hooks for nearly everything. But before we can write the actual code to rename the Divi Project menu entry, labels, icon, etc., we need a way to deploy it to our website. To do this, we have two options. We either can use a Child Theme or a Plugin. The most common way to modify Divi is using a Child Theme, and it’s easy enough to create one on your own or even easier by using our Divi Child Theme Generator.

Once you have your Child Theme or Plugin ready, let’s get to write some code. The first thing we want to do is to change the name and slug of the Projects post type. This can be done by hooking info the register_post_type_args filter:


// Register our own function so it gets called when WordPress fires the filter
add_filter('register_post_type_args', 'dp_register_post_type_args', 10, 2);
function dp_register_post_type_args($args, $post_type) {

	// Check if the filter is fired for the projects post type. If not, we have nothing to do
	if ('project' !== $post_type) {
		return $args;
	}

	// Now that we are sure that we are changing the projects, alter the labels
	$new_plural_name = "My Plural Name";
	$new_singular_name = "My Singular Name";
	$new_slug = "my-custom-slug";

	$args['labels']['name'] = $new_plural_name;
	$args['labels']['singular_name'] = $new_singular_name;
	$args['labels']['menu_name'] = $new_plural_name;
	$args['labels']['name_admin_bar'] = $new_singular_name;
	$args['labels']['add_new_item'] = 'Add New ' . $new_singular_name;
	$args['labels']['edit_item'] = 'Edit ' . $new_singular_name;
	$args['labels']['view_item'] = 'View ' . $new_singular_name;
	$args['labels']['search_items'] = 'Search ' . $new_plural_name;
	$args['labels']['all_items'] = 'All ' . $new_plural_name;
	$args['rewrite']['slug'] = $new_slug;

	// Flushing the rewrite rules should make sure that you don't have to re-save your permalink structure
	flush_rewrite_rules();

	// Finally return or altered labels
	return $args;
}

There you go. This already changed the Project post type name in the menu as well as the slug on the frontend. But there is just one minor issue left. If you go to the Categories/Tags, you’ll notice that it stills says “Project Categories” and “Project Tags”.

So lets quickly fix this as well by utilizing the register_taxonomy_args filter:

add_filter('register_taxonomy_args', 'dp_register_taxonomy_args', 10, 3);
function dp_register_taxonomy_args($args, $taxonomy, $object_type){
	
	// The labels we are going to use
	$new_singular_name = "My Singular Name";
	$new_plural_name = "My Singular Name";

	// If it's either the project_category taxonomy, we apply the new name
	if ('project_category' == $taxonomy) {
		$args['labels']['name'] = $new_plural_name . ' Categories';
		$args['labels']['singular_name'] = $new_singular_name . ' Category';
	}

	// Or if it's the project_tag taxonomy, we apply the new name
	if ('project_tag' == $taxonomy) {
		$args['labels']['name'] = $new_plural_name . ' Tags';
		$args['labels']['singular_name'] = $new_singular_name . ' Tag';
	}

	// Finally return the taxonomy_args
	return $args;
}

Now we are talking! However, this is just the tip of the iceberg. The rest is up to you. Check out the documentations (and contributions at the bottom) of those hooks I have mentioned above. You will find many other interesting options to pass as argument in those functions. Take for example the option menu_icon for the function register_post_type, which you can pass directly into $args. The option is used to, well sherlock, you guessed it 🤓, change the menu icon of Divis Project post type. Simply use one of the WordPress Dashicons or a base64 encoded SVG icon:

// This is how you use Dashicons
$args['menu_icon'] = 'dashicons-book';

//This is how you use SVG icons
$args['menu_icon'] = 'data:image/svg+xml;base64,' . base64_encode('');
And that’s it. That’s basically all the code you need. Either place it in your plugin or the functions.php of your Child Theme and you are done. Or simply use Divi Pixel to do the job. 😉 We are going to provide much more valuable content, so if you have any suggestions for the next tutorial, please leave a comment below!
Jan Thielemann

Jan Thielemann

Jan is the co-founder of Divi Pixel. He is a professional software developer who started developing for WordPress as a hobby. When he made his first contact with Divi in 2016, he immediately saw the potential. Shortly after he developed his first Divi plugin, which was a huge success, he started a side business selling various Divi related products. He's an expert known throughout the whole Divi developer community.