i want to output html tags in do_shortcode(); function

<?php echo do_shortcode($content); ?>

is it possible? thx!

  • Hi. isn't this <?php echo '<html/>'; ?> really doing it?
    – Ismail
    May 9, 2015 at 22:17

2 Answers 2


Yes it is possible.

There are two ways that I can think of at this moment.

First follow what the codex says Shortcodes. Basically you just wrap your html in ob_start(); this will return the html as a string so you can echo it.

function my_shortcode() {
    ?> <HTML> <here> ... <?php
    return ob_get_clean();

The second way is to add your html as a string to a variable then return it later. eg.

function my_shortcode() {
    $output = '';
    $output.= '<html>content</html>';
    return $output;

My solution was, and perfectly works fine for me

function my_function(){
    echo 'Long html tag here';
    $output = ob_get_contents();
    return  $output;

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.