user1548981 user1548981 - 7 months ago 15
HTML Question

Wordpress shortcode is returning changed html

I have a WordPress shortcode function that for debug proposes i reduce it to only these 2 lines

$detail='<div class="property_design_intext_details"><p style="text-align: right;"><div id="add_favorites" class="isnotfavorite" data-postid="132">add to favorites</div></p></div>';
return $detail;


The problem appears on front end where wordpress is displaying other code. More exactly (taken from view source)

<div class="property_design_intext_details"><p style="text-align: right;"><div id="add_favorites" class="isnotfavorite" data-postid="132">add to favorites</div></div>


The closing
</p>
tag is missing.

Any idea about why this is happening and how i can prevent it.

Answer

Browser fixes your broken HTML.

Do not put <div> inside <p>.

It is impossible to place a <div> element inside a <p> in the DOM because the opening <div> tag will automatically close the <p> element.

Comments