Hello can you help me,
i want to add shortcode after this <div
and <div
this is the complete code i added in the function.php
add_action( 'storefront_footer', 'fuyn_footer_widgets', 11 );
function fuyn_footer_widgets(){
if( is_checkout() ){
global $woocommerce ;
if ( $woocommerce->cart->total != 0 ) {
return;
}
echo '<div style="width: 100%;display: flex;">
<div style="width: 50%;background: bisque;margin: 5px;">Shortcode.</div>
<div style="width: 50%;background: bisque;margin: 5px;">Shortcode.</div>
</div>';
}
}
how to do it,
this is my short code
[sc name="ads"][/sc]
Thank you
CodePudding user response:
You can use do_shortcode()
add_action( 'storefront_footer', 'fuyn_footer_widgets', 11 );
function fuyn_footer_widgets(){
if( is_checkout() ){
global $woocommerce ;
if ( $woocommerce->cart->total != 0 ) {
return;
}
echo '<div style="width: 100%;display: flex;">
<div style="width: 50%;background: bisque;margin: 5px;">Shortcode.</div> ' . do_shortcode( '[sc name="ads"]' ) . '
<div style="width: 50%;background: bisque;margin: 5px;">Shortcode.</div>
</div>';
}
}
CodePudding user response:
To add a shortcode inside a PHP code on WordPress. You need to use do_shortcode() like this:
add_action( 'storefront_footer', 'fuyn_footer_widgets', 11 );
function fuyn_footer_widgets(){
if( is_checkout() ){
global $woocommerce ;
if ( $woocommerce->cart->total != 0 ) {
return;
}
echo '<div style="width: 100%;display: flex;">
<div style="width: 50%;background: bisque;margin: 5px;">'.do_shortcode('[sc name="ads"]').'</div>
<div style="width: 50%;background: bisque;margin: 5px;">'.do_shortcode('[sc name="ads"]').'</div>
</div>';
}
}
You can also structure it better like this:
add_action( 'storefront_footer', 'fuyn_footer_widgets', 11 );
function fuyn_footer_widgets(){
if( is_checkout() ){
global $woocommerce ;
if ( $woocommerce->cart->total != 0 ) {
return;
}
$shortcodeValue = do_shortcode('[sc name="ads"]');
?>
<div style="width: 100%;display: flex;">
<div style="width: 50%;background: bisque;margin: 5px;">
<?php echo $shortcodeValue; ?>
</div>
<div style="width: 50%;background: bisque;margin: 5px;">
<?php echo $shortcodeValue;?>
</div>
</div>
<?php } } ?>
OR
add_action( 'storefront_footer', 'fuyn_footer_widgets', 11 );
function fuyn_footer_widgets(){
if( is_checkout() ){
global $woocommerce ;
if ( $woocommerce->cart->total != 0 ) {
return;
}
$shortcodeValue = do_shortcode('[sc name="ads"]');
?>
echo '<div style="width: 100%;display: flex;">
<div style="width: 50%;background: bisque;margin: 5px;">'.$shortcodeValue.'</div>
<div style="width: 50%;background: bisque;margin: 5px;">'.$shortcodeValue.'</div>
</div>';
}
}
Note: do_shortcode()
always requires an echo
.