在 functions.php 中使用 php 向 html 元素添加属性

Add attribute to html element with php in functions.php

我需要 php functions.php (Wordpress) 的代码,以便将属性 (data-priority="2") 添加到具有以下属性的元素:data-name="cf_post_wish_count"

我有

<th data-name="cf_post_wish_count"></th>

我需要

<th data-name="cf_post_wish_count" data-priority="2"></th>

有什么帮助吗?

根据您的描述,这个问题更适合JS/JQuery。您可以相当简单地在前端执行此操作:

$('th[data-name="cf_post_wish_count"]').each(function() {
     $(this).attr('data-priority', '2');
});