spencer-f
12/25/2014 - 5:35 PM

WordPress remove wpautop <p> tags around buttons

WordPress remove wpautop

tags around buttons

/*-- http://wordpress.stackexchange.com/questions/130075/stop-wordpress-automatically-adding-br-tags-to-post-content ---*/

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

function wpse_wpautop_nobr( $content ) {
    return wpautop( $content, false );
}

add_filter( 'the_content', 'wpse_wpautop_nobr' );
add_filter( 'the_excerpt', 'wpse_wpautop_nobr' );



/*---http://blog.iamcreative.me/code-snippets/remove-phantom-paragraph-tags-iframes-images-wordpress/#.VJxHdAAt --*/

// Solution: filter the <p> tags from around buttons
function filter_ptags_on_buttons($content)
{
return preg_replace('/<p>\s*(<button .*>*.<\/button>)\s*<\/p>/iU', '\1', $content);
}
add_filter('the_content', 'filter_ptags_on_buttons');