Web Dev Tuts

/ Stuffs About Website Development /

Menu
  • Home
  • Wp Plugins
  • How To
  • FAQ
    • GIT
    • JQuery
    • PHP
    • WooCommerce
    • WordPress
  • Contact Us
Menu

Apply a Shortcode within a Shortcode

Posted on June 10, 2012September 24, 2017 by admin

Suppose that you have two shortcodes,

1. the [RED]content[/RED] – will change the color of the text to red.

1. the [DOTTED]content[/DOTTED] – will add dotted underline to the text.

{code}function shortcode_red($atts, $content){
return ‘<span style=”color:red”>’.$content.'</span>’;
}

add_shortcode(‘RED’, ‘shortcode_red’);

function shortcode_dotted($atts, $content){
return ‘<span style=”border-bottom:dotted gray 1px”>’.$content.'</span>’;
}

add_shortcode(‘DOTTED’, ‘shortcode_dotted’);{/code}

 

Adding “[RED]this is red[/RED] [DOTTED]this is dotted[/DOTTED]” to the post content, the result is fine. However, when placing the ” [DOTTED]this is dotted[/DOTTED]” inside [RED][/RED] as in “[RED][DOTTED]this is dotted[/DOTTED][/RED]”, will result to a problem. The [DOTTED] shortcode won’t be executed.

 

To fix this, on the return statement, add do_shortcode() function.

{code}function shortcode_red($atts, $content){
return do_shortcode(‘<span style=”color:red”>’.$content.'</span>’);
}

add_shortcode(‘RED’, ‘shortcode_red’);

function shortcode_dotted($atts, $content){
return do_shortcode(‘<span style=”border-bottom:dotted gray 1px”>’.$content.'</span>’);
}

add_shortcode(‘DOTTED’, ‘shortcode_dotted’);{/code}

 

Category: Wordpress

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to add wp_editor Dynamically
  • How to Hide Certain Pages from Certain Users (WP Dashboard)
  • How to Set Up Gmail SMTP
  • How to Set Up Virtual Host in Localhost & Xampp
  • How to Determine the Current WordPress Version Used
  • AngularJs
  • CSS
  • For Me Only
  • geo location api
  • GIT
  • GoDaddy
  • Hosting
  • How To
  • Javascript
  • JQuery
  • Magento
  • My Notes
  • PHP
  • Private
  • Sass
  • WooCommerce
  • Wordpress
  • Xampp
© 2023 Web Dev Tuts | Powered by Minimalist Blog WordPress Theme