You Really Don’t Need a Plugin to Create a Custom Post Type in WordPress

There are a ton of custom post type plugins out there, but honestly, they are almost wholly unnecessary for developers. If you’re comfortable with editing some basic php code, you can create your own custom post type quickly and easily. Really, even those who are not familiar with PHP could accomplish this same task themselves, as it really only requires editing a pre-existing sample of code.

Here is the basic code needed to create a custom post type, as outlined here: https://codex.wordpress.org/Post_Types

add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'acme_product',
    array(
      'labels' => array(
        'name' => __( 'Products' ),
        'singular_name' => __( 'Product' )
      ),
      'public' => true,
      'has_archive' => true,
    )
  );
}

You can place this code in the functions.php file of your theme. I would assume most developers are already aware of this file. Those who are not, and are unfamiliar with accessing files via FTP, you can add this code to your functions.php file via the WordPress administration panel. Simply navigate to your admin panel (at /wp-admin) and select “editor” under the “Appearance” menu (these are on the left). It is possible that you do not have access to the editor, depending on how you setup WordPress. Some hosts use one-click install applications that disable the file editor. Assuming you were able to access the editor just fine, you will want to look to the right for your theme’s function file. Select this file, and add the code above…making sure to replace the sample data with what you need. So, “Product” might become “Article” and “acme_product” might become “my_arcticles”. “acme_product” in the above instance represents the name of the post type itself. This is how it will be referenced in other code throughout the theme. The “Product” label refers to how the post type is labeled in menus and displayed in HTML on the front-end of the site.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>