0

I have made a custom popup tiny mce button to add source code.This put shortcode like this

[source]
<h1>Hi</h1>
[/source]

To capture output I used

function caption_shortcode( $atts, $content = null ) {
$content = do_shortcode($content);
return '<span itemprop="articleSection">'.wpautop($content).'</span>';
}
add_shortcode( 'source', 'caption_shortcode' );

This doesn't show <h1>Hi</h1> rather it convert h1 html tag.How can I make this show like <h1>Hi</h1>?

1
  • You know that wpautop() is used to replace line breaks with paragraphs? And that would make the HTML perfectly invalid.
    – kaiser
    Oct 24, 2014 at 20:18

1 Answer 1

0

Try the following code:

function caption_shortcode( $atts, $content = null ) {
    $content = do_shortcode($content);
    return '<span itemprop="articleSection">'. str_replace( array( '<', '>' ), array( '&lt;', '&gt;' ), $content ) .'</span>';
}
add_shortcode( 'source', 'caption_shortcode' );

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.