3

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? – Samuel Elh May 9 '15 at 22:17
10

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() {
    ob_start();
    ?> <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;
}
-1

My solution was, and perfectly works fine for me

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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