DEV Community

Ahmod Musa
Ahmod Musa

Posted on • Originally published at ahmodmusa.com

Stop Bloating Your WordPress Site: Register CPTs with Code (No Plugin Needed)

We need to talk about our "Plugin Addiction" in the WordPress community.

As developers, we often prioritize speed of development over the quality of the codebase. The biggest culprit? Custom Post Type UI (CPT UI).

Don't get me wrong—it’s a great tool for non-coders. But if you call yourself a WordPress Developer or Engineer, you shouldn't rely on a GUI wrapper to execute a core WordPress function.

The Engineering Problem 🛠️

When you use a plugin to register a "Portfolio" or "Services" post type, here is what happens under the hood:

Database Queries: The plugin stores your CPT settings in the wp_options table. WordPress has to query this on every page load.
Admin Bloat: It adds a menu item and settings pages that your client doesn't need to see (and might break).
Dependency Hell: You are adding another plugin to your update list for a feature that should be native to the theme.
The Native Solution (The functions.php Way) ⚡

Registering a post type requires one function: register_post_type().

By moving this logic to your theme (or a site-specific plugin), you gain:

Version Control: You can track changes in Git.
Performance: PHP execution is faster than database queries.
Immutability: Clients can't accidentally delete the post type from the WP Dashboard.
"But I don't want to write the labels array manually..."

I get it. Writing out 'add_new_item' => 'Add New Project' 20 times is boring.

That's why I created a Production-Ready Snippet that you can just copy and paste.

It includes: ✅ Full support for Gutenberg (Block Editor) (show_in_rest => true). ✅ Custom Dashicons. ✅ Clean Admin Labels.

You don't need to reinvent the wheel. Just copy the code, drop it into your functions.php, and you have a fully functional Portfolio section in 30 seconds.

Get the Code Snippet 👨‍💻

I have hosted the full, clean code snippet on my personal blog to keep it updated.

Top comments (0)