同样是在开发吃货主题Chihuo，导航菜单中的二级菜单需要显示省份的小地图，也就是分类菜单中显示自定义的字段，我们可通过以下代码来实现这个功能。

1. //向菜单中添加分类自定义值
2. function be\_header\_menu\_desc( $item\_output, $item, $depth, $args ) {
3. if( ‘header-menu’ == $args-&gt;theme\_location &amp;&amp; get\_option(‘thumb-‘.$item-&gt;object\_id) )
4. $item\_output = str\_replace( $args-&gt;link\_before . ‘&lt;/a&gt;’, ‘&lt;img src=“‘.get\_option(‘thumb-‘.$item-&gt;object\_id).'” alt=“‘.$item-&gt;title.'”&gt;’.$args-&gt;link\_before.'&lt;/a&gt;’, $item\_output );
5. return $item\_output;
6. }
7. add\_filter( ‘walker\_nav\_menu\_start\_el’, ‘be\_header\_menu\_desc’, 10, 4 );

将以上代码添加到主题 functions.php 函数文件中。

分类中设置自定义字段请查看：[WordPress 为分类添加自定义值](https://api.salongweb.com/wordpress-custom-category-field.html)