bricks_create_menu

Phase 3IntermediateComplexity: 5/10
Create a navigation menu with menu items

Overview

Creates a new WordPress navigation menu with items and optionally assigns it to a theme location. Menu items support multiple object types (page, post, custom URL, category, tag) and nested children for dropdown submenus.

This tool is typically used during Phase 3 when creating header and footer templates. The created menu can then be assigned to a nav-menu element using bricks_assign_menu_to_element.

Key Features

Nested Submenus
Items support children arrays for creating dropdown/flyout submenus to any nesting depth.
Multiple Object Types
Link to pages, posts, categories, tags by ID, or use custom URLs for external links.
Location Assignment
Optionally assign the menu to a theme location (primary, footer, mobile) in the same call.
CSS Classes
Each menu item can have custom CSS classes for targeted styling.

When to Use

During Phase 3 when creating header and footer templates that need navigation
To create a main navigation, footer links, or mobile-specific menu
When the site needs a new menu for a sidebar, mega menu, or utility navigation
After all pages are created so real URLs can be used instead of placeholders
Prerequisites
Pages should ideally be created first so you can link to real page IDs instead of using placeholder # URLs

When NOT to Use

When a menu with the same purpose already exists — use bricks_update_menu instead
When you just need to change a menu assignment on an element — use bricks_assign_menu_to_element

Parameters

3 Total Parameters2 Required1 Optional
namestringREQUIRED
Menu name displayed in WordPress admin (e.g., "Main Navigation", "Footer Links").
itemsarrayREQUIRED
Array of menu item objects. Each item has: title (string), url (string, for custom links), object_type ("page"|"post"|"custom"|"category"|"tag"), object_id (number, for page/post/term links), target ("_self"|"_blank"), css_classes (array of strings), children (nested items array).
locationstringoptional
Theme menu location to assign (e.g., "primary", "footer", "mobile").

Code Examples


Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12

Create Main Navigation

Creates a main navigation menu with a dropdown submenu under Services and assigns it to the primary theme location.

JSON
bricks_create_menu({
  name: "Main Navigation",
  items: [
    { title: "Home", object_type: "page", object_id: 33 },
    { title: "Services", object_type: "page", object_id: 45,
      children: [
        { title: "Web Design", object_type: "page", object_id: 46 },
        { title: "Development", object_type: "page", object_id: 47 }
      ]
    },
    { title: "About", object_type: "page", object_id: 50 },
    { title: "Contact", object_type: "page", object_id: 55 }
  ],
  location: "primary"
})

Common Mistakes


Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018

Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48

Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
If pages have been created, link to them via object_type "page" + object_id instead of using custom URLs with "#". This ensures links stay valid even if page slugs change.

Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018

Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48

Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Creating a menu and assigning it to a theme location is not enough. You also need to use bricks_assign_menu_to_element to connect it to the nav-menu element in your header or footer template.

Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018

Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48

Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
If you create the menu before all pages exist, some items will have placeholder URLs. Always run bricks_scan_links after all pages are created to find and fix stale links with bricks_update_links.

Tips & Warnings

Tips & Warnings

Default URL trap: When using object_type « custom » without specifying a url, WordPress defaults to « # ». Always provide a real URL or use page/post object types with object_id instead.

Mega menus: To convert a menu item into a rich mega menu, first create the menu normally, then use bricks_create_mega_menu to assign a Bricks template to a specific menu item.

Return Values

FieldTypeDescription
successbooleanWhether the menu was created successfully
menu_idnumberThe WordPress term_id of the created menu
namestringThe menu name
items_countnumberTotal number of menu items created
locationstringAssigned theme location if provided

Related Tools

Technical Details

Tool ID
bricks_create_menu
API Endpoint
/menus
HTTP Method
POST
Namespace
wordpress-site
Source File
wordpress/menus.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release
20250101