How can I define a custom template for woocommerce [products] shortcode? [closed]

Open your theme’s function.php and add following add_action( ‘woocommerce_shortcode_before_products_loop’, ‘roka_before_products_shortcode_loop’, 1, 10 ); add_action( ‘woocommerce_shortcode_after_products_loop’, ‘roka_after_products_shortcode_loop’, 0, 10 ); function roka_before_products_shortcode_loop( $atts ) { $GLOBALS[ ‘roka_woocommerce_loop_template’ ] = ( isset( $atts[ ‘class’ ] ) ? $atts[ ‘class’ ] : ” ); } function roka_after_products_shortcode_loop( $atts ) { $GLOBALS[ ‘roka_woocommerce_loop_template’ ] = ”; } Then override … Read more

What characters are allowed as a shortcode tag and how should they be sanitized?

You can use almost every character. Just the character / is dangerous. Do not allow it. WordPress is using preg_quote to escape the shortcode name, but it doesn’t include its own regex delimiter / when doing that. So the shortcode will not be properly escaped and you get a PHP warning. Besides that, there are … Read more

Shortcode adding p and br tags

Not sure if this will be helpful to anyone else but the cause of the issue was a custom formatter the theme had: function my_formatter($content) { $new_content=””; $pattern_full=”{(\[raw\].*?\[/raw\])}is”; $pattern_contents=”{\[raw\](.*?)\[/raw\]}is”; $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($pieces as $piece) { if (preg_match($pattern_contents, $piece, $matches)) { $new_content .= $matches[1]; } else { $new_content .= wptexturize(wpautop($piece)); } … Read more

Allowing shortcodes inside attributes

Sorry, brackets are still not allowed within shortcodes, as you can see in the Shortcode API. However it’s possible to use enclosing shortcodes which will allow to use brackets. Let me demonstrate this: Shortcode: [foo bar=”No brackets here!”]…use [brackets] here[/foo] You can add this kind of shortcode in your functions.php like this: add_shortcode( ‘foo’, ‘foo_shortcode’ … Read more

How to prevent newline from appearing in shortcode?

The <br> tag is coming from wpautop(), which is one of a number of display filters added to the content via wp-includes/default-filters.php: // Display filters add_filter( ‘the_content’, ‘wptexturize’ ); add_filter( ‘the_content’, ‘convert_smilies’, 20 ); add_filter( ‘the_content’, ‘wpautop’ ); add_filter( ‘the_content’, ‘shortcode_unautop’ ); add_filter( ‘the_content’, ‘prepend_attachment’ ); add_filter( ‘the_content’, ‘wp_make_content_images_responsive’ ); … // Shortcodes add_filter( ‘the_content’, … Read more

Add custom shortcode button to Editor

I found it, WordPress made changes and you can now add buttons through a simple API if( !function_exists(‘_add_my_quicktags’) ){ function _add_my_quicktags() { ?> <script type=”text/javascript”> /* Add custom Quicktag buttons to the editor WordPress ver. 3.3 and above only * * Params for this are: * string id Required. Button HTML ID * string display … Read more