I would like to insert a php code, but the error when placing
Shortcode generated by theme
[col_grid span="4" span__sm="14" height="1-2" visibility="show-for-medium"]
[ux_banner height="500px" bg="***[banner-picture]***" bg_size="original"]
[text_box width="100" scale="148" position_x="50" position_y="100" bg="rgb(88, 32, 123)"]
[ux_text text_color="rgb(247, 128, 44)" class="uppercase"]
<p><strong>preencha a proposta de adesão</strong></p>
[/ux_text]
[/text_box]
[/ux_banner]
[/col_grid]
My PHP CODE
add_action('foto_banner', 10 );
function foto_banner() { ?>
<?php if(get_field('foto_banner')) { ?>
<?php the_field('foto_banner'); ?>
<?php }else{
echo "Texto não informado";
}
}
add_shortcode( 'banner-picture', 'foto_banner');
2
Answers
You can write your shortcode like this:
Make sure to add current page id in
get_field()
second parameter oroption
if you are fetching from Theme Options page.You can not put PHP functions inside your shortcode.
However, you do not need to. You can just use your foreach-loop to create the html and store it in a variable, for example $shortcodehtml.
So, afterwards, you can call
The better version of that would be if you would create the output inside the shortcode function – from my point of view it is not necessary to pass the whole html to the shortcode – but this should work fine.