Make WordPress Core

Opened 8 years ago

Closed 10 months ago

#36225 closed enhancement (duplicate)

Cache wp_nav_menu with Transient API

Reported by: ianatkins's profile ianatkins Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.2
Component: Menus Keywords:
Focuses: performance Cc:


Forgive me if I'm wrong but it looks like wp_nav_menu output isn't cached with the transient API. We're manually caching the output in our theme, then clearing the transient on the 'wp_update_nav_menu' hook.

For sites with caching plugins this is obviously redundant, but with dynamic pages (e.g. WooCommerce carts) this would be beneficial.

Change History (11)

#1 @ocean90
8 years ago

Related: #27120, in particular ticket:27120:9.

I don't think that we can store the whole output of that function because it would bypass any filters which could be used by plugins.

#2 @ianatkins
8 years ago

@ocean90 not a WordPress internal's pro, but could the caching not happen on line 452 of wp-includes/nav-menu-template.php - after the filter has been run?

Thanks for digging out the related tickets. Re ticket:27120:9 - whilst caching at a lower level is great, these menu's are relatively intensive to build and it's not uncommon for us to have 4-5 on a page on larger sites. Could be a nice perf gain for a lot of users.

Last edited 8 years ago by ianatkins (previous) (diff)

#3 @swissspidy
8 years ago

#36798 was marked as a duplicate.

#4 @lukecavanagh
8 years ago

I can see this as being a performance gain for WC stores with a fairly large menu built out.

#6 @tazotodua
8 years ago

Last edited 8 years ago by tazotodua (previous) (diff)

#7 @lukecavanagh
7 years ago


This also works very well, using it on a client site.

#8 @szepe.viktor
7 years ago

Core has a lot of caching done in object cache. See post caching for example.

My implementation also works with object cache although it will not work without one.

It has hooks for flushing the nav menu cache on menu editing, and the cache key is

md5( serialize( $args ) . $_SERVER['REQUEST_URI'] )
Last edited 7 years ago by szepe.viktor (previous) (diff)

#9 @tazotodua
6 years ago

it will be good if this topic will be ever implemented.

#10 @hellofromTonya
3 years ago

#41232 was marked as a duplicate.

#11 @spacedmonkey
10 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Marking as duplicate. #27120

Note: See TracTickets for help on using tickets.