johnasp
Member
Posted 2 years ago #
WP is auto inserting <p> tags around my <img> tags - why? Not only is this shifting a unwanted line space at the top of the paragraph of text, but it's also un-semantic.
I'm aware of a plug in that removes all <p>'s from a post but it removes ALL <p> tags which I don't want to happen.
Anyone know where in the source code I can fix this daft error?
Why are <p> tags around images un-semantic? <img> is an inline element and, therefore, the specs dictate that it must be enclosed in a block level element such as <div>. Or <p>. If you use the HTML tab and want to stop <p> tags being inserted, simply surround your image markup with <div> tags.
If the extra space is bothering you, you can always wrap your image in your own <p></p> tags and give the <p> a class, then use CSS to remove any top padding/margin.
johnasp
Member
Posted 2 years ago #
OK wrapping DIV around the images did the trick. Thanks guys.
jpgalea
Member
Posted 2 years ago #
my code is as follows:
<div>
<img>MY IMAGE HERE</img>
<p>MY PARAGRAPH HERE<p>
</div>
but wordpress changes this to
<div>
<p><img>MY IMAGE HERE</img><p>
<p>MY PARAGRAPH HERE<p>
</div>
I don't want those <p> tags around my image, is there a way to disable this auto insertion? thanks