Tutorial by Examples

WordPress shortcodes were introduced in 2.5 Here is come example of shortcode [button] to use shortcode direct into theme you have to use do_shortcode() <?php echo do_shortcode('[button]'); ?> To customize the button, we could simply add something like: [button type="twitter&qu...
The simplest shortcode is the self-closing one. We’re going to create a simple link to our Twitter account, and then add it in a blog post. All the code goes in functions.php, which is located in /wp-content/themes/your-theme/. If you don’t have one, just create it and put the code in it. <?php...
Creating a self-closing shortcode with parameters <?php function button_shortcode( $type ) { extract( shortcode_atts( array( 'type' => 'value' ), $type ) ); // check what type user entered switch ($type) { case 'twitter': ...
enclosing shortcode The enclosing shortcode allows you to embed content within your shortcode, just like BBCode if you’ve ever used that. <?php function button_shortcode( $attr, $content = null ) { return '<a href="http://twitter.com/filipstefansson" class="twitter-button&qu...
By default, WordPress does not support shortcodes within Sidebar Widgets. It only expands the shortcodes within the content of a Post, Page, or custom post type. To add shortcode support to sidebar widgets, you can install a plugin, or use the below code: add_filter( 'widget_text', 'shortcode_unaut...

Page 1 of 1