博客
关于我
wordpress 导航菜单给a标签添加class和data属性
阅读量:726 次
发布时间:2019-03-21

本文共 445 字,大约阅读时间需要 1 分钟。

以下是优化后的内容:

在WordPress开发过程中,有时需要为菜单链接添加额外的属性,如class或数据属性。此时,可以通过在functions.php文件中自定义nav_menu_link_attributes过滤器来实现。

步骤如下:

  • 在functions.php中定义一个新的函数,接收三个参数:$atts(属性数组)、$item(菜单项目)、$args(菜单设置)。
  • 在函数内部为$atts数组添加所需的属性,例如:
    • 添加class属性,设定为所需的class值(例如:'scorll')。
    • 添加data-[key]属性,设定为对应的值(例如:data-link-alt=$item->title)。
  • 将函数注册为nav_menu_link_attributes过滤器,并设置其优先级为10。
  • 这样,菜单链接将带有自定义的class和data属性,既满足开发需求,又有助于后续CSS或JavaScript操作。

    删除残留的无关内容,如地址或图片标签前,确保内容结构和链接逻辑无误。

    转载地址:http://ynbgz.baihongyu.com/

    你可能感兴趣的文章
    nmon_x86_64_centos7工具如何使用
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.7 Parameters vs Hyperparameters
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named 'pandads'
    查看>>
    No module named cv2
    查看>>