I’ve run in to this annoying feature of WordPress before, but mainly with it obsessively <p> tagging everything, this is a little different. I’ve got a bit of php in my themes functions file which loads and parses content from a series of blog posts, grabbing data like links, images and the text and reformatting it… I’m building a client website and trying to make it easy for them to display some offers on the front page, they just need to dump a relevant image, link and a few lines of text in to a blog post and it’ll be read and outputted by this code.
I understand WordPress doesn’t like you wrapping block level elements in <a> tags, which would usually be easily avoidable, except the the text is within <h2> tags which are set to block, so if I try to link them WordPress removes my </a> tag and inserts its own right after the <a>, leaving an empty link.
i.e, I’m expecting (and generating in my php) output like:
<a href="some_url"><h2>Here's my text</h2></a>
…and WordPress is changing it to:
<a href="some_url"></a><h2>Here's my text</h2>
I don’t want to disable error checking etc globally since this is for non-tech savvy clients and they’ll probably need that, so is there a way to disable this on a page-by-page basis – or even better, disable it on a specific section of HTML?
Thanks for any advice!
This is not related to wordpress,this is HTML specification :
This answer is from this Question :
You can only place
<h2>
elements within<a>
elements if you’re working with HTML5, which allows any other elements within<a>
elements. Previous specifications (or current ones however you want to look at them) never allowed this.The usual way of doing this is to place
<a>
within<h2>
. This works, has always worked, and has been the only valid way to do it before HTML5, for heading links, as the link refers to the text in that heading. You rarely need to place<h2>
within<a>
unless that<h2>
is part of some more complex structure which functions as a hyperlink as a whole.