add shortcode for form | WordPress.org

[ad_1]

I wanna create a form with a shortcode so I can use it wherever I need it. I use the below minimal example:


add_shortcode( 'form', 'create_form' );
function create_form () {
    require_once __DIR__ . '/form.php';
}

But when I add the shortcode on the post and try to save it, it shows an error: ‘Updating failed. The response is not a valid JSON response.’

I have also noticed that WordPress specifies this: ‘shortcode should never produce an output of any kind’.

If the shortcode is not meant for making such a task, how do I make a form and add it somewhere? Or the shortcode is okay but I misunderstood and doing something wrong?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer