To hide the Projects post type from your WordPress dashboard, you will need either a plugin or a custom PHP code snippet.
Using a plugin like DiviFlash provides an easy solution with its “Hide Projects Custom Post Type” extension.
In this article, we will show how to hide projects post type in Divi using both the plugin method and a custom code snippet.
Method 1: Hide Projects Post Type in Divi Using DiviFlash
With DiviFlash it’s super easy to hide Projects custom post type in Divi. Here is how to do it:
- Install and activate the DiviFlash plugin.
- From the WordPress dashboard, navigate to DiviFlash > Settings.
- Locate the “Hide Projects Custom Post Type” option and turn it on.
By enabling the “Hide Projects Custom Post Type” option, the “Projects” post type will be hidden from your WordPress dashboard. Besides that projects will no longer show up in search results, and any attempts to visit a project’s specific URL will result in a “404 Not Found” error.
Here is the final result:
Method 2: Hide Projects Post Type in Divi Using a Code Snippet
While DiviFlash makes it easy to remove Projects from Divi, you can do the same using a customPHP code snippet.
Here is how:
- Navigate to WordPress dashboard > Appearance > Theme File Editor
- Click on the “functions.php file” from the theme editor.
- Scroll to the bottom of the functions.php file and paste the following PHP code:
// Hide Divi Projects from the WordPress dashboard
function remove_divi_projects_menu() {
remove_menu_page('edit.php?post_type=project');
}
add_action('admin_menu', 'remove_divi_projects_menu');
// Exclude Divi Projects from search results
function exclude_divi_projects_from_search($query) {
if ($query->is_search() && !is_admin()) {
// Get all registered post types
$post_types = get_post_types(array('public' => true), 'names');
// Remove 'project' from the array of post types
if (($key = array_search('project', $post_types)) !== false) {
unset($post_types[$key]);
}
// Set the query to use the modified list of post types
$query->set('post_type', $post_types);
}
return $query;
}
add_filter('pre_get_posts', 'exclude_divi_projects_from_search');
// Return 404 for Divi Project URLs
function return_404_for_projects() {
if (is_singular('project')) {
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part(404); // Load the 404 template
exit();
}
}
add_action('template_redirect', 'return_404_for_projects');
- Now click Update File to save your changes.
This code snippet will hide “Project” from the WordPress dashboard, search results, and return a 404 error when someone tries to access project URLs directly.
Note: It’s never advisable to add any code directly to the theme’s functions.php file, as it can cause errors or loss of functionality. Instead, use a child theme for such modifications.
Conclusion
Now you know how to hide projects post type in Divi. By using either DiviFlash plugin or a custom code snippet, you can manage the “Projects” visibility.
However, be cautious when using custom code snippets, as they can sometimes interfere with other plugins or theme elements.
Also, it’s often safer to go for the DiviFlash plugin, which provides a built-in feature for disabling “Projects” from Divi.
Note: If you are already a DiviFlash user, update the plugin to access the new “Hide Projects Custom Post Type” feature.
0 Comments