Skip to content

3. Adding Menus and Custom Post Types

Julien Verneaut edited this page Sep 11, 2024 · 1 revision

Managing Menus and Custom Post Types in App.php

The App.php file located at /web/app/themes/theme/app/App.php is responsible for registering menus and custom post types (CPTs) in the theme. It uses two theme-defined services: MenuBuilder and CPTBuilder, making it easy to manage these elements directly from a single location.

Overview

The App.php class uses the MenuBuilder and CPTBuilder services to simplify menu and CPT creation. Here's how it works:

MenuBuilder for Menus

The MenuBuilder service allows you to easily define and register WordPress menus. In this example, two menus are registered:

$menuBuilder
    ->addMenu('primary', 'Primary Navigation')
    ->addMenu('footer', 'Footer Navigation');

CPTBuilder for Custom Post Types

The CPTBuilder service helps you create custom post types without needing to write extensive code in your theme files. Although it’s currently commented out, the following example shows how a custom post type can be easily added:

// $cptBuilder
//     ->addCPT('Employee', 'Employees');

This would register a custom post type called Employee, which would be displayed as Employees in the WordPress admin panel.

Clone this wiki locally