Home > database >  Add attribute to html element with php in functions.php
Add attribute to html element with php in functions.php

Time:02-13

I need php code for functions.php (Wordpress) to add an attribute (data-priority="2") to an element if it have attribute: data-name="cf_post_wish_count"

I have

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

I need

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

Any help?

CodePudding user response:

Based on your description this problem is more suited for JS/JQuery. You can do this on the frontend fairly simply:

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