• I’m working on a project that I inherited so I’m not sure why the previous developers did this, but they added a border-top to the paragraph tags, which is fine until I started seeing lines where they shouldn’t be on the page.

    When I look at the page’s source code, there’s empty paragraph tags there. However, when I look at the template source code, there’s no paragraph tags there, just newlines. For instance:

    <?php if($product[‘sku’]) { ?><p>SKU: <?php echo $product[‘sku’]; ?></p><? } ?>
    <?php $shortdesc = substr(trim($product[‘short_description’]), 0, 384); ?>
    <?php if($shortdesc) { ?>
    <p><?php echo $shortdesc; ?></p>
    <?php } ?>
    <?php foreach($product[‘prices’] as $storeProduct) :… etc

    Even if there’s a sku and a shortdesc, empty paragraph tags get inserted under them. From what I’ve read, WordPress’ runs the wpautop function which replaces double-newlines with paragraph tags, which I don’t actually have there, but PHP removes the line break after the close tag anyways for some practical reason (don’t remember what exactly), so when PHP parses the code it should have already stripped off the newline after the closing tag so there is no newline between these open/close tags for WordPress to even check, much less see two in a row.

    I’m baffled at this, I thought wpautop only applied to Editor text (though it should only apply to Visual text and just leave HTML alone).

    Please I’m looking for a solution to prevent this rather than changing the CSS, HTML, and PHP in the template or custom CSS files.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress adding paragraph tags from newlines in template file code’ is closed to new replies.