Creating a table from shortcode avoiding wpautop for each row

The extra space comes from wpautop(), which inserts <br /> on every line break. You have to strip these out before calling do_shortcode().

Additionally, use add_filter( 'the_content', 'shortcode_unautop' );. From my experience, you need both. Probably a bug.

See my shortcode plugin for an example. It has shortcodes for tables too.

Aside: Shortcodes should never be part of a theme, because you lock yourself or your client into using that theme now. See Justin Tadlock’s article.

Leave a Comment