Stop WordPress automatically showing

tags

前端 未结 7 2379
猫巷女王i
猫巷女王i 2021-01-02 13:05

Wordpress automatically generate lot of unwanted

tags every where. Even the img tag also wrap by these

t

7条回答
  •  猫巷女王i
    2021-01-02 13:33

    There are lots of plugin to disable autop in WordPress or you can use following filter to remove autop:

    remove_filter( 'the_content', 'wpautop' );
    

    However, if you need to style and format content from wp-editor, you will not be able to do so if you have removed autop.

    If you want to continue using autop functionality but want to remove empty p tag you can do it using jQuery.

    I am able to remove unwanted empty p tags using following codes:

    jQuery(document).ready(function(){
        $ = jQuery; 
        $('p').each(function() {
        var $this = $(this);
        if($this.html().replace(/\s| /g, '').length == 0)
            $this.remove();
    }); 
    
    });
    

提交回复
热议问题