I have to add shortcodes for example image, hr and button. However, I additionally required to take away the wpautop filter (remove_filter('the_content','wpautop')) for hr to operate correctly. Now, to by hand set paraghraps I set a shortcode pto merely convert [p]text[/p] with <p>text</p>.

But, inside [p /] another shortcodes aren't working. I suppose it modifies this content. Here's my simple function:

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

I am getting a little nervous with this particular, as my functions.php appears to become filled with hacks already. Any advice?

Martti Laine

I am speculating you have to remove wpautop for the hr shortcode because it will get covered with a paragraph?

If that's the case, only use your shortcode like so


Some text during my editor.

[hr]

A little more text.

Begin to see the line break spacing? WordPress will instantly make sure that shortcode 'by itself' will not get covered with sentences.

I'd strongly advise heading down the path you're right now - if what I have pointed out above is not the issue, what is? Let us take a look at dealing with it instead of re-inventing the wheel!

For that record, if you want to apply nested shortcode, from the codex

When the attaching shortcode is supposed allowing other shortcodes in the output, the handler function can call do_shortcode() recursively:

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