How to Rename Projects Tab on the Divi Website
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:
- How to solve the issue with Divi Pixel
- How to solve the issue using some fairly simple code
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
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('');
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.
Enhance your Divi Theme with Custom Settings and New Modules. Start Creating Awesome Websites with the Divi Pixel
We offer a 14 Day Money Back Guarantee, so joining is Risk-Free!
Thanks, pretty useful information!
Hi Jan,
Awesome tutorial and awesome Plugin – love it so far!
I actually have a suggestion for another tutorial.
I would like to set a specific page as a (custom) post types parent.
The reason for that is, that at the moment your (very useful) Breadcrumb Module will only show the Home Page (ID 0) as an ancestor for all Post types. if I could change the Parent ID of a Post Type, this would actually fix this issue.
Thanks!
Oliver
Hi Oliver 🙂 We are about releasing version 1.10.0 where we have made significant improvements on Breadcrumb module. You will be able to select the post type, taxonomy, change the base URL and more!
This is so cool and helpful. Thanks!
Is there a way to also change the icon displayed in the dashboard?
It is possible Scott. We have updated the tutorial with the additional code needed to change the Dashboard icon as well 🙂
Thank you, that was helpful!
I also included $args[‘rewrite’][‘slug’] = $new_slug; in the taxonomies code so it changes the URL too.
Hi Jan and many thanks for your tutorial.
I had it to my website under development and it works very well.
Is it possible to rename the /project_category/ in the archive pages ?
Example : https://lesrelaismoto.pixeligo.pro/project_category/relais-moto/ for the “relais-moto” category ?
Regards
Pascal
Hi Pascal,
this solution works for me:
if (‘project_category’ == $taxonomy) {
$args[‘labels’][‘name’] = $new_plural_name . ‘ Categories’;
$args[‘labels’][‘singular_name’] = $new_singular_name . ‘ Category’;
$args[‘rewrite’][‘slug’] = ‘custom-slug-here’;
}
Thanks Jan for this tutorial.