Try wrapping the link in the heading instead:
<div>
<h4><a href="#">Text</a></h4>
</div>
Thanks Samuel.
What you’re proposing works for simple cases (such as my example). I wouldn’t know how to implement it in a situation I come across very often, when I have to wrap a larger chunk of code with a tags.
e.g.
<a href="#"><div>Content</div><h4>Header</h4></a>
which turns into:
<div>Content</div>
<h4>Header</h4>
@trizonia,
All those HTML elements ( headings, divisions ) must be out of the a href element.
To code a good HTML, you must wrap the href in those elements, not the opposite. And you shall repeat the linking for every element:
<div>
<a href="#">Content</a>
</div>
<h4>
<a href="#">Header</a>
</h4>
If you insist to put it this way [<a href="#"><div>Content</div><h4>Header</h4></a>
] which WP is correcting in the editor, you can create a custom template for that post or page and code without getting WP to correct the syntax. But, that is considered a bad HTML
and search engines like Google don’t like it.
Samuel,
First of all, thank you for your reply.
After doing some research, I have found all sources stating that since HTML5, this is perfectly valid. As stated here:
http://www.w3.org/TR/html5/text-level-semantics.html#the-a-element
“The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links).”
Also, I found no evidence that Google doesn’t like it; sure, if you wrap an entire article in a tags, it wouldn’t be that great, but for a small banner with text and an image, I doubt (and found no evince that) they care.
Besides, before HTML5 people would use Javascript to the same effect – because the need existed then, as it does now.
The solution you propose results in something other than what I want, which is: A clickable area with a link, which is highlighted as one when one hovers over it and which contains various text tags and possibly an image.
So, since HTML5 considers this valid practice, why does WordPress not allow it? Even if it weren’t the best code possible, I think it’s a rather dictatorial behavior of WordPress to impose its code view on its users.
@trizonia I’m frustrated by this issue. Our content editors are frequently breaking the front page of our site because of it. Have you found any solution?