Skip to content

Instantly share code, notes, and snippets.

@teknikqa
Created June 1, 2021 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teknikqa/c656bb96809e4bfde3843975b6fd2457 to your computer and use it in GitHub Desktop.
Save teknikqa/c656bb96809e4bfde3843975b6fd2457 to your computer and use it in GitHub Desktop.
Disable the default post type on sites that do not need it.
<?php
/**
* WordPress Theme constants and setup functions
*
* @package WPCustomTheme
*/
/*
* When using WordPress as a CMS the Posts content type might not be useful or
* required on some sites. While WordPress provides a way to deregister custom
* post type, the default Post type in WordPress cannot be dergegistered or
* disabled. It can only be hidden. A few caveats:
* * New posts can still be created using the direct link.
* * Existing posts are not affected and will continue to load publicly.
* * Editing exisiting posts will not be possible.
* * Multisite will still show a menu item to create new posts.
*/
add_action( 'wp_dashboard_setup', 'remove_draft_widget', 999 );
add_filter( 'register_post_type_args', 'remove_default_post_type', 0, 2 );
/**
* Remove Quick Draft Dashboard Widget
*/
function remove_draft_widget() {
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
}
/**
* Remove access to the Post type as well as hide it from the menu
*
* @param array $args The array of arguments for registering a post type.
* @param string $post_type The post type.
* @return array
*/
function remove_default_post_type( $args, $post_type ) {
if ( 'post' === $post_type ) {
$args['public'] = false;
$args['show_ui'] = false;
$args['show_in_menu'] = false;
$args['show_in_admin_bar'] = false;
$args['show_in_nav_menus'] = false;
$args['can_export'] = false;
$args['has_archive'] = false;
$args['exclude_from_search'] = true;
$args['publicly_queryable'] = false;
$args['show_in_rest'] = false;
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment