Shortcode inside shortcode not working in Wordpress?

I need to add shortcodes such as image, hr and button. However, I also needed to remove the wpautop filter (remove_filter('the_content','wpautop')) for hr to work properly. Now, to manually set paraghraps I set a shortcode pto simply convert [p]text[/p] with <p>text</p>.

But, inside [p /] the other shortcodes aren't working. I guess that it modifies the content. Here's my simple function:

function p_func($atts,$content) {
    return '<p>'.$content.'</p>';

I'm getting a bit nervous with this, as my functions.php seems to be full of hacks already. Any advice?

Martti Laine


I'm guessing you need to remove wpautop for your hr shortcode as it gets wrapped in a paragraph?

If so, just use your shortcode like so;

Some text in my editor.


A bit more text.

See the line break spacing? WordPress will automatically ensure that shortcode 'by itself' won't get wrapped in paragraphs.

I'd strongly advise going down the route you are at the moment - if what I've mentioned above isn't the problem, what is? Let's look at tackling it rather than re-inventing the wheel!

For the record, if you need to apply nested shortcode, from the codex;

If the enclosing shortcode is intended to permit other shortcodes in its output, the handler function can call do_shortcode() recursively:

function caption_shortcode( $atts, $content = null ) {
   return '<span class="caption">' . do_shortcode($content) . '</span>';

Need Your Help

Netfilter in Kernel Module causes my system to crash

linux-kernel kernel-module netfilter

I have written this Kernel Module and everytime I load it, it crashes the whole system(even my keyboard leds start flashing)

Yii Pre-loading form text fields from another model

yii textfield preloading

I am trying to pre-load the text fields from another model, I used the following code not working, here is my code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.