Skip to content

Instantly share code, notes, and snippets.

@senlin
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senlin/41dbe77976bc7dc99fd3 to your computer and use it in GitHub Desktop.
Save senlin/41dbe77976bc7dc99fd3 to your computer and use it in GitHub Desktop.
Issue with WordPress shortcodes When I insert '[button]Button text[/button]' into a page, automatically <br /> tags comes before and after it, but I do not want that to happen. OP: https://www.linkedin.com/groups/Issue-WordPress-shortcodes-3722491.S.5993861951699058688
<?php
function sButton( $atts, $content = null ) {
extract(shortcode_atts(
array(
'link' => '#',
'grootte' => 'klein',
'id' => '1',
'randen' => ''
), $atts )
);
return '<a class="button-' . $id . ' ' . $grootte . ' ' . $randen . '" href="' . $link . '"><span>' . do_shortcode( $content ) . '</span></a>';
}
add_shortcode( 'button', 'sButton' );
//add_filter( 'widget_text', 'do_shortcode' ); not related to shortcode itself
<?php
/**
* WP Core function `shortcode_unautop` seems broken
* good hack is to replace the unwanted output
*
* @source: http://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/
*/
function so_remove_autop_shortcodes( $content ) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr( $content, $array );
return $content;
}
add_filter( 'the_content', 'so_remove_autop_shortcodes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment