WordPress: Disable "Add New" on Custom Post Type

Cover Image for WordPress: Disable "Add New" on Custom Post Type
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

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. 🌟

  1. Install and activate the Adminimize plugin from the WordPress Plugin Directory.

  2. Once activated, go to Settings -> Adminimize to configure the plugin.

  3. Find the section labeled Post types and click on it.

  4. Locate the checkbox next to your Custom Post Type (e.g., Portfolio), and uncheck the option that says "Add new."

  5. 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. 😎

  1. Access your WordPress theme files, and locate the functions.php file for your active theme.

  2. 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');
  1. 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'.

  2. 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! 🎉🎈


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello