admin管理员组文章数量:1122832
I'm using the Press Customizr theme. I need to add an ID (not class) to an existing HTML element from the theme (specifically it's the Related posts section)
Is there a way I can do this with a filter/hook? The element has an existing class, so if I could target that element via its class and add a unique ID to it, without removing the class.
I'm using the Press Customizr theme. I need to add an ID (not class) to an existing HTML element from the theme (specifically it's the Related posts section)
Is there a way I can do this with a filter/hook? The element has an existing class, so if I could target that element via its class and add a unique ID to it, without removing the class.
Share Improve this question asked Jan 13, 2019 at 9:24 BYellowJBYellowJ 11 bronze badge 4- There is no filter for arbitrarily changing HTML elements. There can't be. You will need to check with the theme documentation and author to see if there's something in your theme that will let you do this. – Jacob Peattie Commented Jan 13, 2019 at 9:54
- Well in that case the only solution would be to add an empty html element right next to the one I want to target. Is that possible? How do I add a new element while using "right after X element" as its location? – BYellowJ Commented Jan 13, 2019 at 10:00
- You can’t do that either. Everything you’re asking would require support from the theme. – Jacob Peattie Commented Jan 13, 2019 at 12:01
- 1 So you know, technically yes you can do that with JavaScript, i.e. jQuery('.the-existing-class').attr( 'id', 'the-id-you-want' ). However you can't be sure there aren't multiple elements with that class, and the code would apply to all of them unless you limited it. It's still a backwards way of thinking though. Adding something to the DOM like this should be done before the page is given to the browser, which is in the realm of the theme. – tmdesigned Commented Jan 13, 2019 at 12:05
1 Answer
Reset to default 3You can add an ID:
Going to the settings area of the block.
Scroll down and expand the "Advanced" section.
Add the ID name you want in the HTML Anchor box. Don't use the hashtag in front of the name. That is added automatically by WP.
本文标签: How to add an ID to an existing HTML element
版权声明:本文标题:How to add an ID to an existing HTML element? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304104a1932117.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论