This is my first time asking a question here. I'm kinda stuck on how to do echo do_shortcode();
inside a shortcode.
I tried googling for an answer but to no avail.
I'd like to know if it is possible to echo a shortcode inside a shortcode. If it is, any pointer is much appreciated.
Thank you.
function cpa_haven_banner() {
return '
<ul class="list-group list-group-horizontal entry-meta">
<li class="list-group-item list-group-action-item">
<strong>Female</strong> <?php echo do_shortcode("[get_sheet_value location='LOAN!B7']"); ?>
</li>
</ul>
';
}
add_shortcode('cpa-haven', 'cpa_haven_banner');
This is my first time asking a question here. I'm kinda stuck on how to do echo do_shortcode();
inside a shortcode.
I tried googling for an answer but to no avail.
I'd like to know if it is possible to echo a shortcode inside a shortcode. If it is, any pointer is much appreciated.
Thank you.
function cpa_haven_banner() {
return '
<ul class="list-group list-group-horizontal entry-meta">
<li class="list-group-item list-group-action-item">
<strong>Female</strong> <?php echo do_shortcode("[get_sheet_value location='LOAN!B7']"); ?>
</li>
</ul>
';
}
add_shortcode('cpa-haven', 'cpa_haven_banner');
Share
Improve this question
asked Aug 10, 2020 at 12:18
yansusantoyansusanto
1092 bronze badges
2 Answers
Reset to default 1This should work:
function cpa_haven_banner() {
$shortcode = do_shortcode("[get_sheet_value location='LOAN!B7']");
return '
<ul class="list-group list-group-horizontal entry-meta">
<li class="list-group-item list-group-action-item">
<strong>Female</strong> ' . $shortcode .
'</li>
</ul>
';
}
add_shortcode('cpa-haven', 'cpa_haven_banner');
I would put all the markup in a variable, and return the result of passing that through do_shortcode
:
function cpa_haven_banner() {
$html = '
<ul class="list-group list-group-horizontal entry-meta">
<li class="list-group-item list-group-action-item">
<strong>Female</strong> [get_sheet_value location=\'LOAN!B7\']
</li>
</ul>
';
return do_shortcode( $html );
}
add_shortcode('cpa-haven', 'cpa_haven_banner');