**Using the Nav Menu Field**


目录

Basic Setup

To get started with the Nav Menu Field in SCF, follow these steps to configure and display a WordPress navigation menu:

Step 1: Create a New Field Group

First, create a new field group in Secure Custom Fields (SCF). This field group will hold your custom fields, including the Nav Menu field.

  1. Go to Custom Fields > Add New in your WordPress admin panel.
  2. Title your field group and choose the location rules for where this field group should be displayed (e.g., on a specific page or post type).

Step 2: Add a Nav Menu Field

Once you've created a new field group, add a new field of type Nav Menu. This field will allow users to select a navigation menu from the available menus on your site.

  1. Click Add Field within the field group.
  2. Set the Field Type to Nav Menu.
  3. Configure the necessary field options based on your needs.

Step 3: Configure Options

Configure the field options for the Nav Menu field to tailor it to your needs.

Code Example: Basic Setup

Here's how you can implement the Nav Menu Field in a template file:

// Check if the Nav Menu Field has a value
$menu_id = get_field('your_nav_menu_field_name');

if ($menu_id) {
    // Get the menu object or HTML based on your configuration
    $menu_html = wp_nav_menu(array(
        'menu'      => $menu_id,  // Use the menu ID
        'container' => 'nav',      // Use a 'nav' container
        'echo'      => false,      // Don't output directly; return the HTML
    ));

    echo $menu_html; // Output the menu HTML
}

Common Use Cases

  1. Use to Output WordPress Navigation Menu Anywhere:
    The Nav Menu Field allows you to output a WordPress navigation menu in custom locations across your site, such as in custom templates, widgets, or shortcodes.

Tips


版本号 #2
由 壳壳虫 创建于 2026-08-29 14:50:46 UTC
由 壳壳虫 更新于 2026-08-29 14:50:46 UTC