OCMLABS/MODULE-WORDPRESS · MENUS

Show a WordPress navigation menu in the Magento blog sidebar

  • Magento
  • Adobe Commerce
  • Hyvä

The Menus group shows a menu from WordPress Appearance > Menus in the blog sidebar. You build and order the menu in WordPress, and the blog sidebar in Magento follows it.

Admin path: Stores > Configuration > OCMLabs > WordPress Integration > Menus

Settings

Enable WordPress Menus

Turns WordPress menus on. When set to No, no menu requests are made to WordPress and no WordPress menu is rendered.

  • Default: No

The WordPress menu to show at the top of the blog sidebar, directly under the search box. The list shows every menu under Appearance > Menus in WordPress. This field appears when Enable WordPress Menus is Yes.

  • Default: None
  • Save the connection settings first, so the list can load from WordPress
  • Can be set per website or store view
  • Added in 2.1.0

The menu shows on the blog home, category, tag and search pages and on single posts, on Luma and Hyva. The other sidebar blocks (categories, recent posts, tags, archive) stay below it. Author pages have no sidebar. If the page layout is set to 1 column, there is no sidebar to show it in.

Nested menu items show as an indented list under their parent. The menu’s name from WordPress is used as the block heading.

Menu items that point at WordPress content are rewritten to their blog address in Magento, so visitors stay on the store:

Menu item in WordPressLink in Magento
Post/blog/{post-slug}
Category/blog/category/{slug}
Tag/blog/tag/{slug}
The page set as the WordPress front page/blog
Custom link to a WordPress URLThe same path under /blog
Any other WordPress pageUnchanged, opens on WordPress
Custom link to another siteUnchanged
NOTE /

Links are only rewritten when they start with the WordPress URL in the Connection settings. Enter the same address WordPress uses for itself (Settings > General > Site Address in WordPress). If the two differ, for example an internal host name in Magento and a public one in WordPress, menu links keep pointing at WordPress.

Adding a Menu Elsewhere

To place a WordPress menu anywhere else, such as the header or footer, add the menu block in your theme’s layout XML and name the menu with the menu_slug argument:

XML LAYOUT
<block class="OCMLabs\WordPressIntegration\Block\Menu\WordPress"
       name="wordpress.menu.footer"
       template="OCMLabs_WordPressIntegration::menu/wordpress.phtml">
    <arguments>
        <argument name="menu_slug" xsi:type="string">footer</argument>
    </arguments>
</block>

menu_slug accepts a menu slug from Appearance > Menus or a theme menu location such as primary. Without it, the block shows the Sidebar Menu. Enable WordPress Menus must be Yes for either to render.

menu/wordpress.phtml renders a horizontal menu. Submenus open on hover on Luma and with Alpine.js on Hyva. For a vertical list like the blog sidebar, use OCMLabs_WordPressIntegration::sidebar/menu.phtml.

The module reads menus from the plugin’s oc-bridge/v1/menus endpoints. /wp-json/oc-bridge/v1/menus/{slug} returns one menu with its nested items:

JSON
{
  "id": 10,
  "name": "Blog Sidebar",
  "slug": "blog-sidebar",
  "location": [],
  "items": [
    {
      "id": 28,
      "title": "Technology",
      "url": "https://blog.example.com/category/technology/",
      "type": "taxonomy",
      "object": "category",
      "object_id": 3,
      "target": "",
      "classes": [],
      "description": "",
      "children": [
        {
          "id": 30,
          "title": "Business",
          "url": "https://blog.example.com/category/business/",
          "type": "taxonomy",
          "object": "category",
          "object_id": 4,
          "target": "",
          "classes": [],
          "description": "",
          "children": []
        }
      ]
    }
  ]
}

Cache

NOTE /

Menu data is cached with the WORDPRESS_MENU cache tag. When a WordPress navigation menu is updated, the Content Bridge plugin sends a webhook that purges this tag, so the next page load fetches the new menu. Pages that show a menu carry the same tag, so the full page cache is cleared for them too.

See also

Related pages

In this module