When Should You Use a Custom Post Type?

Services: Law Firm Website Design . SEO . Internet Marketing . Law Firm Marketing Guide . Content Marketing . PPC

Custom post types are one of the most powerful features in WordPress. They allow you to create and organize content and display it on your website however you want. This post provides an overview to help you understand how and when to use them.

What Are Custom Post Types?

Custom post types are a way of extending the functionality of WordPress. By default, WordPress comes with two main content types: posts and pages. However, with custom post types, you can add new content types that better suit your needs. For example, most of our sites use custom post types such as Attorneys, Practice Areas, and Offices. We use these custom post types to better organize your content into different areas instead of adding all the above into the default custom post type “pages”. There are other cases where we will create specific custom post types to meet the needs of our clients.

How to Create a Custom Post Type

Custom post types can be created with a plugin or by adding a few lines of code to your website’s functions file. Using code can be more complicated but in the long run it is the preferred solution. Plugins can bloat websites, by loading in more files that can be unnecessary, and have the potential of causing plugin conflict with existing plugins.

However, if you’re not comfortable coding in PHP, please consult your web design/development company for assistance. 

Below is a snippet example of a function that creates a Books post type.

function create_books_post_type() {
  $labels = array(
    "name" => _x("Books", "post type general name"),
    "singular_name" => _x("Book", "post type singular name"),
    "add_new" => _x("Add New", "Client"),
    "add_new_item" => __("Add New Book"),
    "edit_item" => __("Edit Book"),
    "new_item" => __("New Book"),
    "view_item" => __("View Book"),
    "search_items" => __("Search Books"),
    "not_found" =>  __("No Books found"),
    "not_found_in_trash" => __("No Books found in Trash"),
    "parent_item_colon" => "Parent Book"

      "labels" => $labels,
      "public" => true,
      "supports" => array("title", "page-attributes", "editor", "thumbnail", "custom-fields", "revisions"),
      "hierarchical" => true,
      'show_in_rest' => true,
      "menu_icon" => "dashicons-paperclip",
      "show_in_nav_menus" => true,
      "rewrite" => array("with_front" => false)
add_action("init", "create_books_post_type");

There is a lot of information on the web and on WordPress’s official documentation of the register_post_type() function on what all the parameters in the function do, and how they function.

Once this is all setup, content can start to be added in the WordPress admin. But in addition a template will need to be set in order to properly view the content added to the new custom post type. 

Based on the WordPress file hierarchy, if a template is not set up for the custom post type, typically WordPress will default to index.php if no template is set up, and the styling may not be ideal for viewing. A template can be set by creating a file in the root directory of your current theme, and naming the file using the word single followed by a dash, and the name of the registered post type. In the case of our example we would have: single-books.php

Custom post types are not always needed, and can be avoided. But in certain situations they can provide great content organization on the frontend and backend. Please consult your web design/development company if you’re not comfortable with coding, and they will be able to assist with getting this setup.

Related Posts