Recently I was building a plugin and I wanted to remove the functionality to add a new post in my custom post type. Basically the custom post type interface needed to be just a means for the user to see what that data about that custom post type was stored in the database. Turns out it’s not that straightforward to do at the moment, however as always there is a way to achieve what we want:
First Possible Solution: CSS
Via CSS you can use ‘display:none’ to remove the elements we don’t need from the dashboard menu. However they would still be accessible via direct URL. Not really that effective, although it somewhat does the job.
Second Possible Solution: Making your post type live as a submenu page
There is a show_in_menu flag we can use when creating a new custom post type. This optionally takes a string that identifies the top-level menu it should fall under. Set show_in_menu to tools.php, and suddenly you have a menu under Tools. It’s important to note that in this case, the Add New entry and any taxonomies will not be listed in the submenu — you’ll have to handle those yourself on a case-by-case basis, if you want them. This still ain’t a complete solution, the Add new post is just hidden and still accessible with a direct URL. Also on the post list, we still get the ‘Add new post’ button. There should be something more effective….
Third Possible Solution:
The third and best solution I’ve found is taken from a plugin called Log Deprecated Notices by Andrew Nacin. He uses various techniques to achieve exactly what we’re after, although I think it’s still quite hacky. It’s quite a challenge to explain here, so just view the source of that plugin and you’ll see what he does. Be warned, this is for experienced devs only.
A post on Minimalbugs also deals with this problem in a similar fashion, and is quite well explained.
Do you have any other solutions?
If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.