AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
835 stars 171 forks source link

Shortcodews not working in ACF WYSIWYG + unable to submit a support message on acf website #790

Closed Romain-BASE-GVA closed 1 year ago

Romain-BASE-GVA commented 1 year ago

Hi, I'm trying to print a custom shortcode in ACF Wysiwyg, but it's not working.

my shortcode:


function uppercase( $atts , $content = null ) {

    return '<span class="uppercase">' . $content . '</span>';

}
add_shortcode( '[uppercase]', 'uppercase' );

how it is return in my template :

<?php elseif ($type == 'text') :
   $text = get_sub_field('text');
   $fontSizeClass = 'text--fs-' . get_sub_field('font_size');
   $textWidthClass = 'text--w-' . get_sub_field('text_width');
   $textAlignmentClass = 'text-' . get_sub_field('text_alignment');
?>
   <div class="slide__layer slide__layer--text">
      <div class="text <?php echo $textWidthClass;
         echo ' ' . $fontSizeClass;
         echo ' ' . $textAlignmentClass; ?>">
      <div>
      <?php echo $text; ?>
   </div>
   </div>
   </div>
<?php endif; ?>

the way I insert it in the wysiwyg :

[uppercase] AK66 150 x 150 cm [/uppercase]

and the shortcode is not rendered, it returns [uppercase] AK66 150 x 150 cm [/uppercase] on the front-end.

It looks like other people have the same issue but no clear answers on how to fix that has been provided on ACF forum (at least not after an hour of research) or anywhere else.

Is it even possible to use custom shortcodes in the ACF Wysiwyg? Is there some documentation on the ACF Website that I missed?

Wordpress version : 6.1.1 ACF Version : Advanced Custom Fields PRO 6.0.7

Thank you.

lgladdy commented 1 year ago

You'd need to apply the do_shortcode function if you want to parse shortcodes in an ACF field.

Something like $text = do_shortcode( get_sub_field('text') );