My theme need to render 2 menus in homepage. The rest pages only need one. As result is only homepage got duplicate query warning. After tracking down, I found out this was cause by wp_nav_menu
. How do I avoid this problem?
Here is the screenshot of my duplication warning:
SELECT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
WHERE t.term_id = 163
And its caller:
- Lucidy\header()
wp-content/themes/lucidy/engines/linker.php:86 - Lucidy\render()
wp-content/themes/lucidy/engines/linker.php:79 - Lucidy\load()
wp-content/themes/lucidy/engines/linker.php:48 - wp_nav_menu()
wp-includes/nav-menu-template.php:120 - wp_get_nav_menu_object()
wp-includes/nav-menu.php:26 - get_term()
wp-includes/taxonomy.php:834 - WP_Term::get_instance()
wp-includes/class-wp-term.php:131
According to debugger, potential troublemakers are get_term_link
and get_term_field
. However, I can be very sure that I don't directly use them. It must be called from the wp_nav_menu
. The wp_nav_menu
is the main suspect because in other page, such as archive page or singular page, I couldn't find any duplication warning.
Is this the core bug? Anyway, how do I avoid it? My theme has been slow recently (up to 0.30s~0.60s rendering time for homepage) so I would like to optimize it very much.
[Update 5-Otc]
Sorry, I forgot to share my menu info. I actually has 3 menu locations and 2 of them are placed in homepage. At homepage I use wp_nav_menu
2 times.
I register those in functions.php
:
register_nav_menus([
'menu_col' => __('Menu Column', 'lucidy'),
'menu_list' => __('Menu List', 'lucidy'),
'menu_bar' => __('Menu Bar', 'lucidy')
]);