Hello
I wish create my shortcode with my ACF field.
I did it like this:
function horairesEte() {
if( have_rows('horaires_ete', 'option') ):
while ( have_rows('horaires_ete', 'option') ) : the_row();
return '<span class="jours">'.the_sub_field('jours').'</span><span class="ouverture">'.the_sub_field('ouverture').'</span>-<span class="fermeture">'.the_sub_field('fermeture').'</span>';
endwhile;
endif;
}
add_shortcode('horaires_ete', 'horairesEte');
But it’s returning my fields outside the <spans>
Someone knows how to resolve it ?
thanks
Hi,
Could you try this…
function horairesEte() {
ob_start();
if( have_rows('horaires_ete', 'option') ):
while ( have_rows('horaires_ete', 'option') ) : the_row();
return '<span class="jours">'.the_sub_field('jours').'</span><span class="ouverture">'.the_sub_field('ouverture').'</span>-<span class="fermeture">'.the_sub_field('fermeture').'</span>';
endwhile;
endif;
return ob_get_clean();
}
add_shortcode('horaires_ete', 'horairesEte');
I think you have to use get_sub_field
instead of the_sub_field
…
function horairesEte() {
if( have_rows('horaires_ete', 'option') ):
while ( have_rows('horaires_ete', 'option') ) : the_row();
return '<span class="jours">'.get_sub_field('jours').'</span><span class="ouverture">'.get_sub_field('ouverture').'</span>-<span class="fermeture">'.get_sub_field('fermeture').'</span>';
endwhile;
endif;
}
add_shortcode('horaires_ete', 'horairesEte');