最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

navigation - Can I now add a class in the anchor of my menu item with Wordpress 5.4?

programmeradmin2浏览0评论

I am using the following code in my functions.php file:

function add_menuclass($ulclass) {
return preg_replace('/<a title="All"/', '<a title="All" class="addition-of-class-name"', $ulclass, 1);
}
add_filter('wp_nav_menu','add_menuclass');

So, as you can see, I am checking for a menu item anchor and then adding a class in the anchor that comes after the menu item snippet that I have configured in my Wordpress site.

<li class="class-added-by-wp-menu-item-already">
   <a class="CAN-I-ADD-A-CLASS-WITH-THE-NEW-FIELD-HERE-NOW?">
   </a>
</li>

/

Can I now do this with the new functionalities in Wordpress 5.4 / to be precise:

wp_nav_menu_item_custom_fields
wp_nav_menu_item_custom_fields_customize_template

Or did I misread?

发布评论

评论列表(0)

  1. 暂无评论