[ad_1]
Hey everyone,
what is the best way to output html via a shortcode?
Variant 1:
function shortcode_callback(){
?>
<p>This is my HTML :)</p>
<?php
}Variant 2:
function shortcode_callback(){
ob_start();
?>
<p>THis is my HTML</p>
<?php
$output = ob_end_clean();
return $output;Variant 3:
function shortcode_callback(){
$html="<p> this is my Html</p>
<div>over multiple lines</div>";
return $html;
}Variant 4:
function shortcode_callback(){
$html="<p>This is my HTML</p>";
$html .= '<div>over multiple lines</div>';
return $html;
}Variant 5:
function shortcode_callback(){
$html="<p>This is my HTML</p>";
$html .= '<div>over multiple lines</div>';
echo $html;
}I tend to go for Variant 4 since variant 1 doesn’t seem right to me, Variant 3 and 4 are kinda just preferances and I like variant 4 more for readability.
Variant 5 is wrong since you shouldn’t echo in plugins right? I just wanted to add it, in case someone wonders the same in the future.
I don’t know about variant 2, I think I saw this somewhere once.
What is the best way tho, I would love to hear your tips.
- This topic was modified 6 hours, 55 minutes ago by .
