最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Line break before headings (<h2>) appears from nowhere

programmeradmin4浏览0评论

So, in the database row i've the following html code in post_content:

Solo pochi giorni fa, esattamente il 15 marzo, è stato presentato durante l'ultima edizione del SXSW Online un suggestivo cortometraggio intitolato <em>Don't Peek - Animal Crossing Horror Short</em> diretto da Julian Terry.
<ul>
    <li><strong>LEGGI ANCHE: </strong><h2 class="h2-link-correlati"><h2 class="h2-link-correlati"><a href="/" rel="bookmark">Animal Crossing: New Horizons è al primo posto tra i videogiochi più venduti del 2020 di Amazon UK e US</a></h2></h2></li>
</ul>
E ora, secondo quanto riportato da <a href="/">Deadline,</a> <strong>Timur Bekmambetov</strong> (<em>Wanted</em>, <em>Hardcore Henry</em>) sarebbe già pronto a realizzare un film horror tratto proprio dal cortometraggio sopracitato.

As you can se there is no line break/br before the .

BUT

In frontend, and in backend (when editing the post), the line break appears. Like new line in the editor and like a
in frontend.

How is it possible?


EDIT:

it seems to be related to the wpautop filter (/) that made this wonderful thing: adding a line break before and after every html block

$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';

// Add a double line break above block-level opening tags.
$pee = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee );

// Add a double line break below block-level closing tags.
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );

My solution was this, but it's pretty ugly:

remove_filter( 'the_content', 'wpautop' );
$br = false;
add_filter( 'the_content', function( $content ) {
    return wpautop( $content, false );
}, 10 );
发布评论

评论列表(0)

  1. 暂无评论