artparks
artparks

Reputation: 761

Wordpress stripping <a href> from shortcodes

I have a fairly straight forward shortcode for making a quote breakout box which is called as:

[jasminesays quote="blah de blah"]

Dead easy. However when I try and put a link inside it wordpress won't return the quote at all. All other HTML that I've tried seems fine, it only seems to fall over with something like:

[jasminesays quote="blah <a href="#">de</a> blah"]

Something like

[jasminesays quote="blah <p>de</p> blah"]

works fine.

The code to process the shortcode is:

function mm_jasmineSays( $atts ) { 
extract( shortcode_atts( array(  
        "quote" => '',
       ), $atts ) );

return '<link href="'.get_bloginfo( 'template_directory' ).'/css/shortcodes.css" rel="stylesheet" type="text/css" />
        <div class="jasmine-says">
            <h2>Jasmine says...</h2>
            <div class="jasmine-says-quote">
                <p><img src="'.get_bloginfo( 'template_directory' ).'/imgs/shortcodes/quote-1.jpg" /></p>
                <p class="quote">'.$quote.'</p>
                <p><img src="'.get_bloginfo( 'template_directory' ).'/imgs/shortcodes/quote-2.jpg" /></p>
            </div>
        </div>';
}
add_shortcode('jasminesays', 'mm_jasmineSays');

but I don't think this is the problem, I'm guessing wordpress is filtering certain things out somewhere and I need to disable this. Anyone have any ideas?

Thanks for any help.

Upvotes: 1

Views: 2995

Answers (3)

why not adding the url option to the shortcode?

Something like adding:

    function mm_jasmineSays( $atts ) { 
extract( shortcode_atts( array(  
"quote" => '',
"url" => '',
), $atts ) );

And then adding

<a href="'.$url.'"> <h2>Jasmine says...</h2></a>

Maybe it could work.. or using the $output instead return like:

global $post;
$output .= '<div class="jasmine-says">';
if($quote !== '')
$output .= '<a href="'.$url.'"><h2>Jasmine says...</h2>';
        $output .= '<div class="jasmine-says-quote">'
            $output .='<p><img src="'.get_bloginfo( 'template_directory' ).'/imgs/shortcodes/quote-1.jpg" /></p>';
            $output .='<p class="quote">'.$quote.'</p>';
            $output .='<p><img src="'.get_bloginfo( 'template_directory' ).'/imgs/shortcodes/quote-2.jpg" /></p>';
        $output .='</div>';
    $output .='</div>';

Upvotes: 0

meeble
meeble

Reputation: 93

Not sure if this will help, but have you tried changing the outer quotes to single quotes?

[jasminesays quote='blah <a href="#">de</a> blah']

or removing the inner quotes?

[jasminesays quote="blah <a href=#>de</a> blah"]

Upvotes: 0

Fernando Briano
Fernando Briano

Reputation: 7768

From WordPress Codex

The return value of a shortcode handler function is inserted into the post content output in place of the shortcode macro. Remember to use return and not echo - anything that is echoed will be output to the browser, but it won't appear in the correct place on the page.

Shortcodes are parsed after wpautop and wptexturize post formatting has been applied (but see the note below about 2.5.0 and 2.5.1 differences). This means that your shortcode output HTML won't automatically have curly quotes applied, p and br tags added, and so on. If you do want your shortcode output to be formatted, you should call wpautop() or wptexturize() directly when you return the output from your shortcode handler.

wpautop recognizes shortcode syntax and will attempt not to wrap p or br tags around shortcodes that stand alone on a line by themselves. Shortcodes intended for use in this manner should ensure that the output is wrapped in an appropriate block tag such as p or div.

Upvotes: 1

Related Questions