Search code examples
htmlwordpressformsshortcode

WP - Use shortcode in HTML form field


I would like to use shortcodes in a HTML form on a Wordpress site.

Example:

  <input type="text" name="EMAIL" value="[shortcode_here]" required />
<input type="submit" value="Submit" />

Now it returns like this while I would like it to return something like this.

Anyone out there able to help?


Solution

  • Found the answer here: https://wordpress.stackexchange.com/questions/195665/why-do-shortcode-is-not-executing-the-shortcode-in-data-html-attributes/195673#195673

    add_filter( 'wp_kses_allowed_html', function ( $allowedposttags, $context ) {
        if ( $context == 'post' ) {
            $allowedposttags['input']['value'] = 1;
        }
        return $allowedposttags;
    }, 10, 2 );