admin管理员组文章数量:1122846
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')
]);
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')
]);
Share
Improve this question
edited Oct 5, 2019 at 3:30
Star Light
asked Oct 4, 2019 at 17:54
Star LightStar Light
518 bronze badges
1 Answer
Reset to default 0You'd avoid it by creating another menu and menu location. You can do this with a widget area or whatever. Then only call the menu if the page is the home page with is_home() or is_front_page() if it is a page.
Here's from twenty seventeen as an example.
register_nav_menus(
array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
)
);
and then it's called like:
<?php if ( has_nav_menu( 'top' ) ) : ?>
<div class="navigation-top">
<div class="wrap">
<?php get_template_part( 'template-parts/navigation/navigation', 'top' ); ?>
</div>
You can pretty much put whatever you want in widget areas though. I use them just incase I wanna stick something else there.
In your situation, menu is the "correct" way to do it though.
本文标签: menusHow to avoid a duplicate query from using wpnavmenu
版权声明:本文标题:menus - How to avoid a duplicate query from using wp_nav_menu? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291222a1928678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论