Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have following shortcode:

function infobox_shortcode( $atts, $content = null ) {

    extract( shortcode_atts( array(
      'src' => '',
      'title' => '',
      'text' => '',
    ), $atts, 'infobox' ) );

    $return = '<div class="infobox clearfix"><div class="col-md-1 infobox-image"><img src="'.$src.'" alt="'.$title.'"/></div><div class="col-md-8 infobox-content"><h2> ' . $title . '</h2><p>' . $text . '</p></div></div>';

    return $return;

}
add_shortcode( 'infobox', 'infobox_shortcode' );

This works fine, when the user uses it simple like so:

[infobox src="http://www.google.com" title="Google" text="Some description"]

But:

As soon as the users tries to add e.g. a link with quotes to the shortcode, it - of course - breaks:

[infobox src="http://www.google.com" title="Google" text="Some description - see more: <a href="http://www.google.com">More here</a>"]

Issue is that my user uses the WP Editor to add a link and this makes double quotes. Alsor WordPress seems to delete single quotes for attributes by default and adds double quotes which then again break my shortcode.

Right now I see 2 solutions for this, but both are not quite satisfying.

a) Tell WP not to convert single quotes to double quotes in a href links while saving a post or b) To make the shortcode work with double quotes.

Any other hints or workarounds I can go with this?

Thanks!

Mike

share|improve this question
    
Since it seems you are writing the shortcode could you not dynamically add the "See More {link}" part within the shortcode? –  codearachnid May 12 at 10:27

1 Answer 1

up vote 3 down vote accepted

Either way this seems like a very clunky solution for arbitrary markup in shortcode.

If only one of attributes is more bulky and includes markup I would consider making shortcode enclosing:

[infobox src="http://www.google.com" title="Google"]
    Some description - see more: <a href="http://www.google.com">More here</a>
[/infobox]

You might be to the point when you'll need to built custom UI or it will just be too error prone for users.

share|improve this answer
    
Hi Rarst, think you are right. The way you pointed out seems much better then enclosing everything in the shortcode brackets [] and quotes. I'll try that, thanks! –  Mike May 12 at 13:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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