WordPress: Disable "Add New" on Custom Post Type
WordPress: Disabling "Add New" on Custom Post Type 🚫👀
So, you want to disable the "Add New" option for a specific Custom Post Type in WordPress 🤔 No worries! I got you covered! 🙌
The Dilemma 😕
Imagine this scenario: you have created a fantastic Custom Post Type, like "Portfolio" or "Testimonials," and you want to prevent anyone from accidentally creating new posts under that specific post type. However, you can't seem to find any built-in options to help you achieve this. 😓
The Quest for Solutions 🕵️♀️
Don't panic! There are a few simple solutions to address this issue. Let's explore two of the most popular ones:
Solution 1: Using a Plugin 🧩✨
WordPress is all about plugins! And lucky for us, there's a reliable one that can help us disable the "Add New" option for a Custom Post Type. 🌟
Install and activate the Adminimize plugin from the WordPress Plugin Directory.
Once activated, go to Settings -> Adminimize to configure the plugin.
Find the section labeled Post types and click on it.
Locate the checkbox next to your Custom Post Type (e.g., Portfolio), and uncheck the option that says "Add new."
Save your changes, and voila! Your "Add New" button should now be hidden for your selected post type. 🎉
Solution 2: Custom Code Snippet 🧙♂️💻
For those who prefer a more hands-on approach or want to avoid adding additional plugins, you can achieve the same result by adding a small snippet of custom code to your WordPress theme's functions.php
file. 😎
Access your WordPress theme files, and locate the
functions.php
file for your active theme.Open the
functions.php
file in a text editor and add the following code to the end:
function disable_new_posts() {
global $pagenow;
if (($pagenow == 'post-new.php') && (isset($_GET['post_type']) && $_GET['post_type'] == 'your_custom_post_type')) {
wp_die('This feature is disabled for your Custom Post Type.');
}
}
add_action('admin_init', 'disable_new_posts');
Replace
'your_custom_post_type'
with the slug of your actual Custom Post Type. For example, if your post type is called "Portfolio," your code will be'portfolio'
.Save the changes to
functions.php
and refresh your WordPress dashboard.
Now, if users try to access the "Add New" page for your specified Custom Post Type, they will receive a message indicating that this feature is disabled for them. 🚫🛠️
Take Action! 🚀
There you have it, folks! Two simple ways to disable the "Add New" option for your Custom Post Type in WordPress. ✨
So, go ahead, choose your preferred solution, and bid farewell to accidental new posts under your special post types! 😅
If you found this guide helpful, don't forget to share it with your fellow WordPress enthusiasts! And if you have any questions or other WordPress conundrums, leave a comment below, and let's solve them together! Let's power up our WordPress game! 💪💻
Happy WordPressing! 🎉🎈