Skip to content

Instantly share code, notes, and snippets.

@labsecrets
Last active August 29, 2015 14:12
Show Gist options
  • Save labsecrets/f1f982db45ab1c6a9712 to your computer and use it in GitHub Desktop.
Save labsecrets/f1f982db45ab1c6a9712 to your computer and use it in GitHub Desktop.
WordPress remove wpautop <p> 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment