Memberlite lets you set the layout for single items and archives separately for each post type in the WordPress Customizer. Out of the box, these per-type settings are only available for the custom post types from our Courses for Membership, Series, and Events for Members-Only Add Ons. This code recipe adds any other custom post type to that list, such as events, directory listings, or a post type you built yourself, so it gets its own layout controls too.

Without the recipe, other custom post types use the generic layout from your Posts & Archives settings. With it, you can give your events a grid archive with no sidebar while your blog uses a right sidebar.

Code Recipe: Give Your Custom Post Types Their Own Memberlite Layout Settings, with the Customizer showing Events Layout settings

Best Practices and Considerations

  • Requires Memberlite 8.0 or later: This post covers the settings in Memberlite 8.0.1. In 8.0, each post type gets the layout settings only. The breadcrumb, author block, and prev/next settings for each post type were added in 8.0.1. The filter was added in Memberlite 7.1.2, so the recipe also works on 7.1.x, but the settings there have different names. On any other theme, the recipe does nothing.
  • The post type must already be registered: Memberlite checks each slug against the post types registered on your site. If a slug is misspelled, or the plugin that registers the post type is inactive, Memberlite skips it without showing an error.
  • The post type must have an admin screen: Memberlite skips post types registered with show_ui set to false. These are usually internal post types that a plugin uses behind the scenes, and they would not benefit from layout settings anyway.
  • Test the front end after you add a post type: Some plugins use their own archive or single templates and ignore the theme’s layout. If your new settings do not change anything on the front end, the plugin’s templates are the likely cause.

About the Code Recipe

This recipe uses the memberlite_customizer_cpts filter. This is a Memberlite theme filter, not a PMPro hook. Memberlite uses it to build the list of post types that get their own layout settings. The list starts with four PMPro post types, and Memberlite only includes the ones that are active on your site:

  • pmpro_course (Courses for Membership Add On)
  • pmpro_lesson (lessons from the same Add On)
  • pmpro_series (Series Add On)
  • pmpro_event (Events for Members-Only Add On, version 2.0 and later)

The recipe adds your post type’s slug to the end of that list. Memberlite then creates a layout section for it in the Customizer, under Appearance > Customize > Other Post Types. The section is named after the post type’s plural label, so a post type called “Events” gets an Events Layout section.

Each section starts with an Inherit from Posts & Archives checkbox. While it is checked, the post type uses your Posts & Archives and Breadcrumbs settings. It is checked by default, so adding a post type does not change your site until you uncheck it. Once unchecked, these settings appear. The names below are for a post type called “Events”:

  • Default Single Event Layout: Right Sidebar, Left Sidebar, Narrow, or Contained. This is used on single items of this type unless an item picks its own layout in the editor.
  • Default Event Archive Layout: The same four layouts, used on the post type’s archive page and on the archives of any taxonomy that belongs only to this post type. This setting only appears if the post type has an archive page or a taxonomy of its own.
  • Columns Ratio: How wide the content area is compared to the sidebar. Each layout setting has its own ratio (Single Event Columns Ratio and Event Archive Columns Ratio), and it only appears when that layout is Right Sidebar or Left Sidebar.
  • Archive Display: Show full post content, show excerpts, or show posts in a grid on the post type’s archive page. This setting only appears if the post type has an archive page.
  • Breadcrumbs on Single Events: Show breadcrumbs on single items of this type.
  • Breadcrumbs on Event Archives: Show breadcrumbs on the post type’s archive. Like the archive layout, this setting only appears if the post type has an archive page or a taxonomy of its own.
  • Show Author Block on Events: Show the author bio box below single items.
  • Show Prev/Next on Single Events: Show previous and next links below single items.

The breadcrumb, author block, and prev/next settings start out matching your Posts & Archives and Breadcrumbs settings, so you only need to change the ones you want to be different for this post type.

A post type you add with this recipe also gets the Layout panel in the block editor sidebar, so you can override the default layout for a single event. See the Layout Settings documentation for more on each layout.

Step-by-Step Implementation Guide

Step 1: Find Your Post Type’s Slug

The slug is the internal name WordPress uses for the post type. It is not always the same as the label you see in the admin menu.

  1. In the WordPress admin, click the menu item for your post type (for example, Events).
  2. Look at the URL in your browser’s address bar. It will look like yoursite.com/wp-admin/edit.php?post_type=event.
  3. The text after post_type= is your slug. In this example, the slug is event.

Step 2: Add the Recipe

Copy the code recipe below, replace 'event' with your slug, and add it to your site. The section after the code explains how.

Step 3: Set Up the Layout in the Customizer

  1. Go to Appearance > Customize. You will see a new Other Post Types panel below Pages.
  2. Click Other Post Types, then click the section for your post type (for example, Events Layout).
The Other Post Types panel showing an Events Layout section
  1. Uncheck Inherit from Posts & Archives. Choose a layout for single items and a layout for the archive, then set Archive Display. Turn breadcrumbs, the author block, and prev/next links on or off for this post type.
  2. Visit an archive page or a single post of this type in the Customizer preview to check the result, then click Publish.
The Events Layout section with Inherit from Posts & Archives unchecked and the Default Single Event Layout, Default Event Archive Layout, and Archive Display settings showing

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin, available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Want to tweak this recipe? An AI coding assistant can help you adjust the code to fit your exact needs, or even add it to your site for you. Always test changes on a staging site first and keep a backup.

Rather have us handle it? With PMPro Max, you can submit a Do It For Me request, and our team will review it and, when possible, add or customize this recipe directly on your site.

How to Customize This Code Recipe

  • Set your post type slug (line 23): Replace 'event' with the slug you found in Step 1. Keep the single quotes around it.
  • Add more than one post type: Copy line 23 and paste it directly below, once for each extra post type. Then change the slug on each line. For example:
$cpts[] = 'event';
$cpts[] = 'directory_listing';

Each post type gets its own section under Other Post Types, and you can set up each one separately.



Was this article helpful?
YesNo

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics