Wrap and HTML tags inside content with Shortcode

I have a shortcode for notices which works like this:

[infobox]This is my information text[/infobox]

The code for the infobox look like this:

add_shortcode( ‘infobox’, ‘infobox’ );
function infobox($atts, $content = null) {
return ‘<p class=”infobox”>’ . do_shortcode($content) . ‘</p>’;
}

The infobox is formatted using this:

.infobox{background: none repeat scroll 0 0 #ff9; clear:both; margin-bottom:20px; margin-top:20px; overflow:hidden; border: 1px solid #333; padding:20px;}

My question is; by using my theme’s functions.php file, I am trying to wrap (not remove) all and tags with the infobox shortcode.

Example:

<pre><code>Information here</code></pre>

will become this:

[infobox]<pre><code>Information here</code></pre>[/infobox]

This is the code I am trying to get to work, but without success.
The output I get is this: [infobox]>Information text[/infobox]

Here’s is the full wrap code I am using:

add_filter( ‘the_content’, ‘wrap_content_html_in_shortcode’ , 11 );
function wrap_content_html_in_shortcode($content){
$content = preg_replace(‘/(<pre>)s*(<code)/’,'[info]’, $content);
$content = preg_replace(‘/(</code>)s*(</pre>)/’, ‘[/info]’, $content);
return $content;
}

Any ideas where I’m going wrong?

Read more here:: and HTML tags inside content with Shortcode" rel=nofollow>Wrap

 and  HTML tags inside content with Shortcode

Leave a Reply

Your email address will not be published. Required fields are marked *