remove_filter( 'the_content', 'wpautop' ); is not working for me

I use Tinymce Advanced plugin. I would like to remove p tag by adding this code remove_filter( 'the_content', 'wpautop' ); to my functions.php. However, it does't work. When I press ENTER, it still inserts double line, not single line. The p character still displays at the bottom left of the textarea.

Topic wp-autop Wordpress

Category Web


You can achieve this much easier with css (escpecially for wp-ers who dont have access to edit plugins):

<style>
p:empty{
  height: 0;
  margin: 0;
  padding: 0;
}
</style>

Your code seems pretty correnct. Please check whether your code actually removes wpautop function or not with this below line of code-

var_dump( $wp_filter['the_content'] );

Add it at the end of your functions.php and analyze the output. If the wpautop is still there then either it is getting added after your code is been executed or your code is not been executing at all.

If all the above is good but the code still doesn't work then I can suggest you this below forced removal of those p tag with below code-

add_action( 'admin_print_footer_scripts', 'the_dramatist_remove_wpautop', 100 );
function the_dramatist_remove_wpautop() {
    ?>
    <script type="text/javascript">
        (function($) {
            if ( typeof wp === 'object' && typeof wp.editor === 'object')  {
                wp.editor.autop = function (text) { return text; };
                wp.editor.removep = function (text) { return text; };
            }
        })( jQuery);
    </script> 
    <?php
}

This later block of code isn't tested. Please test it before going live.

Hope the above answer helps.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.