简体   繁体   English

不需要的木材渲染 <p> 和 <br> 古登堡块中的标签

[英]Timber rendering unwanted <p> and <br> tags in Gutenberg blocks

For some reason, my twig templates are rendering empty <p> tags and unwanted <br> tags in my ACF Gutenberg blocks. 由于某些原因,我的树枝模板在ACF Gutenberg块中呈现了空的<p>标签和不需要的<br>标签。

This is causing me to have to remove code indentation and formatting in order to remove these unwanted elements. 这导致我必须删除代码缩进和格式才能删除这些不需要的元素。 For example, I have to change: 例如,我必须更改:

       </div>
    </div>
</div>

to: </div></div></div> 到: </div></div></div>

in order to remove empty paragraphs. 为了删除空的段落。

Is there any way to retain code formatting while preventing these tags? 有什么办法可以在防止这些标签的同时保留代码格式?

Seems to be an issue at this point. 在这一点上似乎是一个问题。 You can use the following workaround 您可以使用以下解决方法

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', function ($content) {
    if (has_blocks()) {
        return $content;
    }

    return wpautop($content);
});

github issue - workaround github问题 - 解决方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM