I've searched a lot but didn't find a solid answer for my question. So I'm posting a new one here. If someone know how to do it, please answer it with an explanation.

Lets say I have a shortcode function

    function some_random_function($atts, $content = null) {
          'text' => null
       ), $atts));

       $return_string = '<div class="some-class">'. $text . $content .'</div>';
       return $return_string;
add_shortcode( 'example', 'some_random_function' );

I know that this function does not make any sense that why I'm using $text there where I can simply use $content. But this is just a simple function do dont judge it.

Now the issue Now if I pass [example text="lorem ipsum"]Lets roll[/example] the shortcode will work fine as all are normal string. But if I pass [example text="<a href="http://example.com">lorem</a> ipsum"]Lets roll[/example] it will not work.

So can anyone tell me how can I pass html in the shortcode arguments so that they work properly.

1 Answer 1


You have used the same quotation characters in 2 different contexts. You should write the shortcode in the following way:

[example text='<a href="http://example.com">lorem</a> ipsum']Lets roll[/example]

Then, "unescape" HTML entities on the shortcode output:

$return_string = '<div class="some-class">'. html_entity_decode($text) . $content .'</div>';
  • Thanks man for pointing out the issue and giving an helpful answer :) Thanks a lot man :)
    – iSaumya
    Mar 15, 2015 at 11:00

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.