0
votes

I've added shortcode to a page via a custom textarea in my Wordpress admin, but the shortcode is seen as text and gets wrapped in quotation marks, so it doesn't work.

enter image description here

This is basically how I sanitize my input:

if( isset( $input['textarea_input'] ) )
        $new_input['textarea_input'] = sanitize_text_field( $input['textarea_input'] );

This is how I output it on the page:

<?php echo $options['textarea_input']; ?>

do_shortcode does not change anything

<?php echo do_shortcode($options['textarea_input']); ?>

My guess is that the Wordpress TinyMCE editor recognizes shortcode, and therefor it works. Since mine is added via a hidden text area, it's just seen as plain text. What does the TinyMCE editor what I'm not doing? I wan't

1
You're echoing a string. I think you are looking for do_shortcode()rnevius
Thank you @rnevius, do_shortcode() does not work. I've updated my answer.piggypig

1 Answers

1
votes

Your sort of right, the Wordpress editor saves content thru a filter called the_content. This filter is used to filter the content of the post after it is retrieved from the database and before it is printed to the screen. Apply this filter to simulate TinyMCE formatting.

<?php echo apply_filters( 'the_content', $options['textarea_input']); ?>