Skip to content

How to Create Forms in WordPress Without Plugin (2026)

Flat contact form window icon beside the title How to Create WordPress Forms Without a Plugin

Here is how to create forms in WordPress without plugin code you cannot read. You need one small file with a shortcode, a handler and four safety checks.

I built and tested the form in this guide in October 2026 on WordPress 7.1.3 with Twenty Twenty-Five. I sent valid messages, spam bot messages, bad emails and forged requests, and I checked what was saved and emailed each time.

This guide walks through the full contact form first. Then it adapts the same code for an event registration form and a payment form, and it covers sending email without a plugin.

Does WordPress Have a Built-In Form Block?

WordPress 7.1.3 has no form block in core. A stock site cannot collect form entries without code or a plugin. The Comments Form block only handles post comments, and Login/out only signs people in. Every other “form” result in the inserter comes from a plugin.

I searched the block inserter for “form” on a clean test site. The results showed Comments Form, Login/out and unrelated blocks such as Preformatted, but no contact form.

WordPress block inserter with no core form block

The Gutenberg plugin did test experimental form blocks for a while. In September 2026 the team removed that experiment in Gutenberg pull request 82451, saying the blocks were no longer being pursued. So guides that tell you to add a core Form block describe a feature you cannot use.

So a WordPress contact form without plugin help needs code or a hosted service, which leaves three routes. You can write a small form yourself, use a hosted form service, or install a form plugin. This guide covers the first route, and the comparison near the end helps you decide.

How to Create Forms in WordPress Without Plugin Code: 6 Steps

Learning how to create forms in WordPress without plugin help starts with one PHP file. It prints the form with a shortcode and handles the submission through admin-post.php. The handler checks a nonce, drops spam, cleans every field, saves the message and emails you, in the order below.

How to create forms in WordPress without plugin in a six step flow

All the code goes in one file. Put it in wp-content/mu-plugins/simple-contact-form.php or in a child theme’s functions.php. A must-use plugin loads on every theme. The form survives a theme change.

Once the form works, learn where to check form submissions in WordPress so no entry gets lost in an inbox.

Do not paste PHP into the Theme File Editor on a live site. One typo there can take the whole site down. Edit the file over FTP or on a staging copy.

Step 1: Save Messages as a Private Post Type

Start with a place to keep messages so a failed email never loses one. A private post type is the simplest choice. WordPress gives it an admin screen, search and trash for free, and it needs no custom table.

add_action( 'init', function () {
	register_post_type( 'contact_message', array(
		'label'           => 'Messages',
		'public'          => false,
		'show_ui'         => true,
		'menu_icon'       => 'dashicons-email',
		'supports'        => array( 'title', 'editor' ),
		'capability_type' => 'post',
		'capabilities'    => array( 'create_posts' => 'do_not_allow' ),
		'map_meta_cap'    => true,
	) );
} );

The public setting keeps messages off the front end and out of search. The create_posts rule hides the Add New button, because messages should only come from the form.

Step 2: Print the Form With a Shortcode

A shortcode lets you place the form on any page with a Shortcode block. The WordPress shortcode API says a shortcode must return its output and never echo it. Output buffering handles that while you write plain HTML.

add_shortcode( 'simple_contact_form', function () {
	$status = isset( $_GET['contact'] ) ? sanitize_key( $_GET['contact'] ) : '';
	ob_start();
	if ( 'sent' === $status ) {
		echo '<p class="contact-notice">Thanks, your message was sent.</p>';
	} elseif ( 'invalid' === $status ) {
		echo '<p class="contact-notice">Please enter your name, a valid email and a message.</p>';
	}
	?>
	<form class="simple-contact-form" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
		<input type="hidden" name="action" value="simple_contact">
		<?php wp_nonce_field( 'simple_contact', 'simple_contact_nonce' ); ?>
		<p><label for="sc-name">Name</label><input id="sc-name" type="text" name="sc_name" required></p>
		<p><label for="sc-email">Email</label><input id="sc-email" type="email" name="sc_email" required></p>
		<p><label for="sc-message">Message</label><textarea id="sc-message" name="sc_message" rows="5" required></textarea></p>
		<p class="sc-hp" aria-hidden="true" style="position:absolute;left:-9999px"><label for="sc-website">Website</label><input id="sc-website" type="text" name="sc_website" tabindex="-1" autocomplete="off"></p>
		<p><button type="submit">Send message</button></p>
	</form>
	<?php
	return ob_get_clean();
} );

The hidden action field tells WordPress which handler to run. The wp_nonce_field() call adds a one-time token, and the Website field is the honeypot from Step 4.

Step 3: Handle the Submission With admin-post.php

Every form on the site can post to admin-post.php, which runs the hook named after the form’s action field. You need two hooks: one for visitors and one for logged-in users. The admin_post hook reference documents both.

add_action( 'admin_post_nopriv_simple_contact', 'simple_contact_handle' );
add_action( 'admin_post_simple_contact', 'simple_contact_handle' );

function simple_contact_handle() {
	$back = wp_get_referer() ? wp_get_referer() : home_url( '/' );

	if ( ! isset( $_POST['simple_contact_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['simple_contact_nonce'] ), 'simple_contact' ) ) {
		wp_die( 'This form has expired. Go back, reload the page and try again.', 'Form expired', array( 'response' => 403 ) );
	}

	// Bots fill every field, people never see this one.
	if ( ! empty( $_POST['sc_website'] ) ) {
		wp_safe_redirect( add_query_arg( 'contact', 'sent', $back ) );
		exit;
	}

	$name    = sanitize_text_field( wp_unslash( $_POST['sc_name'] ?? '' ) );
	$email   = sanitize_email( wp_unslash( $_POST['sc_email'] ?? '' ) );
	$message = sanitize_textarea_field( wp_unslash( $_POST['sc_message'] ?? '' ) );

	if ( '' === $name || ! is_email( $email ) || '' === $message ) {
		wp_safe_redirect( add_query_arg( 'contact', 'invalid', $back ) );
		exit;
	}

	wp_insert_post( array(
		'post_type'    => 'contact_message',
		'post_status'  => 'private',
		'post_title'   => $name . ' (' . $email . ')',
		'post_content' => $message,
	) );

	wp_mail(
		get_option( 'admin_email' ),
		'New contact message from ' . $name,
		$message,
		array( 'Reply-To: ' . $name . ' <' . $email . '>' )
	);

	wp_safe_redirect( add_query_arg( 'contact', 'sent', $back ) );
	exit;
}

Note the exit after every redirect. The wp_safe_redirect reference says the function does not exit by itself. Code after it would keep running.

Step 4: Block Spam With a Nonce and a Honeypot

The nonce and the honeypot stop two different attacks. The nonce proves the request came from your page. A forged post from another site fails. The honeypot catches bots because they fill every field they find, including the one people never see.

A nonce is valid for 12 to 24 hours by default. The wp_verify_nonce reference also warns that nonces are not a login check, which is fine here because the form is public.

The honeypot handler pretends to succeed. A bot that gets an error might try again, while a fake success makes it move on.

Cached pages need care. A page cache can serve an old nonce to many visitors, and after 24 hours those submissions fail. Exclude the contact page from your page cache.

Step 5: Style the Form With CSS

The form uses plain HTML. It takes your theme’s fonts and colors. A few rules make the fields full width and easy to tap on a phone. Add them in Appearance > Customize > Additional CSS or in your child theme’s stylesheet.

.simple-contact-form label { display: block; font-weight: 600; margin-bottom: 4px; }
.simple-contact-form input,
.simple-contact-form textarea { width: 100%; max-width: 520px; padding: 10px; border: 1px solid #c3c4c7; border-radius: 6px; font: inherit; }
.simple-contact-form button { padding: 12px 24px; border: 0; border-radius: 6px; background: #1e1e1e; color: #fff; cursor: pointer; }
.contact-notice { padding: 12px 16px; border-left: 4px solid #2271b1; background: #f0f6fc; }

Each field has a real label tied to it by for and id. Screen readers read the label aloud, and tapping the label focuses the field.

Step 6: Add the Form to a Page and Test It

This is how to create a contact form in WordPress pages without a builder: add a Shortcode block with [simple_contact_form] to a page called Contact. Publish it. Then send a test message while logged out. You should land back on the page with a thank you notice, a new entry under Messages and an email in your inbox.

WordPress contact form without plugin showing the sent message

The saved message shows up in the dashboard under Messages and is marked Private.

Contact form messages saved in the WordPress admin

I tested four cases on the same form:

  • Valid message: Redirected to the sent notice, saved 1 message and sent 1 email.
  • Honeypot filled: Showed the same sent notice to the bot, but saved and emailed nothing.
  • Invalid email: Returned to the form with the error notice, and saved nothing.
  • Wrong nonce: Stopped with a 403 “This form has expired” page, and saved nothing.
WordPress form without plugin test results

How to Send Mail in WordPress Without Plugin Help

WordPress sends mail with its own wp_mail() function. You do not need a plugin to send a message. You pass the recipient, subject, message and optional headers. The catch is delivery: by default it uses PHP mail on your server. Many inboxes treat that as spam.

The wp_mail function reference is clear about the limit. A true result only means WordPress processed the request without errors. It does not prove that anyone received it.

The handler above sets a Reply-To header with the visitor’s address. Click Reply in your inbox and the answer goes to them, while the From address stays on your own domain. Never put the visitor’s address in the From header, because receiving servers reject mail that claims to come from a domain you do not own.

For reliable delivery, send through SMTP with a real mail service. You can do that in code with the phpmailer_init hook:

add_action( 'phpmailer_init', function ( $phpmailer ) {
	$phpmailer->isSMTP();
	$phpmailer->Host       = 'smtp.example.com';
	$phpmailer->Port       = 587;
	$phpmailer->SMTPAuth   = true;
	$phpmailer->SMTPSecure = 'tls';
	$phpmailer->Username   = 'forms@example.com';
	$phpmailer->Password   = SMTP_PASSWORD; // define it in wp-config.php
} );

Keep the password in wp-config.php as a constant and never in the theme. Then set up SPF and DKIM records for your domain with your mail provider. This makes inboxes trust the messages.

How to Create a WordPress Event Registration Form Without a Plugin

An event registration form is the contact form with different fields and a seat limit. Keep the same shortcode, nonce, honeypot and handler. Add fields for the event details, save each signup as a private post, and stop new signups once the saved count reaches your limit.

Swap the message field for the fields you need, such as a ticket count:

<p><label for="sc-seats">Seats</label><input id="sc-seats" type="number" name="sc_seats" min="1" max="4" value="1" required></p>

Then check the limit in the handler before you save:

$seats = min( 4, max( 1, absint( $_POST['sc_seats'] ?? 1 ) ) );
$taken = count( get_posts( array(
	'post_type'   => 'contact_message',
	'post_status' => 'private',
	'numberposts' => -1,
	'fields'      => 'ids',
) ) );
if ( $taken >= 50 ) {
	wp_safe_redirect( add_query_arg( 'contact', 'full', $back ) );
	exit;
}

Change the limit of 50 to your venue size. The count includes every saved signup. Delete test entries before the event opens.

This simple count works for one event per site. For several events, save the event name with each signup and count only the matching ones with a meta_query.

Store the seat count with update_post_meta() after wp_insert_post() returns the new ID. Add a “full” notice to the shortcode, and send the visitor a confirmation with a second wp_mail() call.

For a free event, that covers most needs. For paid tickets, combine it with the payment step below.

How to Create a WordPress Payment Form Without a Plugin

You should not build card handling yourself. A payment form without a plugin uses a hosted payment page. Create a Stripe Payment Link or a PayPal payment link and then send the visitor there after your form saves their details. The card details never touch your site.

Stripe Payment Links work without code on Stripe’s side. You create a link in the Stripe dashboard, and Stripe hosts the checkout page and sends the receipt.

To redirect after saving, swap the last redirect in the handler for the payment link. My test caught a trap here. wp_safe_redirect() only allows your own domain. A redirect to buy.stripe.com quietly went to the admin URL instead.

Allow the Stripe host first:

add_filter( 'allowed_redirect_hosts', function ( $hosts ) {
	$hosts[] = 'buy.stripe.com';
	return $hosts;
} );

With that filter in place, the same redirect went to the Stripe link. Mark the saved entry as paid later from Stripe’s dashboard or email receipt.

If you do not need to collect details first, skip the form. Paste the payment link or Stripe’s buy button into a Custom HTML block.

Custom Form vs a Form Plugin: Which Should You Use?

A custom form suits one or two simple forms on a site where someone can maintain PHP. A plugin suits sites with many forms, file uploads, conditional fields or staff who edit forms themselves. The code is small, but you own every security fix and every new field.

If you need file uploads in your form, you can create a file upload form in WordPress for free with a plugin.

  • Pick custom code: You want one contact form, no extra plugin and full control of the markup.
  • Pick a plugin: You need several forms, file uploads, payments inside the form or a visual builder.
  • Pick a hosted form: You want no code and no plugin, and you accept an embedded third-party form.

Free plugins differ in what they keep. Contact Form 7 and WPForms Lite only email entries, while Fluent Forms saves them. If you add a chat tool instead of a form, our roundup of WordPress chatbot plugins compares the options.

Think about who edits the form next year. A marketer can add a new field in a plugin’s builder in a minute. The same change in code needs a developer and a deploy.

Think about the data too. A plugin with entries, exports and notifications saves you from writing those features yourself, and each one is more code to secure.

Custom code also needs updates. A WordPress care plan usually includes checking that forms still send after core and PHP updates.

Common Problems With Custom WordPress Forms

Most custom form problems come from four places: emails, caching, redirects and file location. Emails land in spam without SMTP, cached pages carry expired nonces, and redirects to other domains fail silently. A code file in the wrong place simply never loads.

  • No email: Send through SMTP and check spam folders first.
  • “This form has expired”: Exclude the form page from the page cache.
  • Redirect goes to the dashboard: Add the external host with allowed_redirect_hosts.
  • Form does not show: Check the file is in wp-content/mu-plugins and the shortcode name matches.
  • Blank page after Send: A PHP error stopped the handler. Turn on WP_DEBUG_LOG and read the log.

Test every change while logged out in a private browser window. Logged-in admins skip some caches and use the other admin_post hook. A form can work for you and fail for visitors.

Watch the Messages list for a week after launch. A sudden stop in new entries is the fastest sign that something broke.

WordPress loads theme files through its template hierarchy, starting from the main template file. Our guide to index.php in WordPress explains why form code belongs in a plugin file instead of a template.

Conclusion

Now you know how to create forms in WordPress without plugin code you do not understand. One file holds the shortcode, the handler and the private post type for saved messages.

The safety checks matter most. Keep the nonce, the honeypot, the sanitizing and the exit after each redirect.

Then extend it with care. Add seats for an event form, redirect to a hosted payment link for paid forms, and send mail through SMTP so messages arrive.

Frequently Asked Questions (FAQs)

Q1. Can I create a form in WordPress without a plugin?

Yes. A shortcode prints the form, admin-post.php receives it and wp_mail() sends it. Add a nonce, a honeypot and sanitizing, as in the code above, and test it while logged out.

Q2. How do I create a contact form in WordPress without a plugin?

Save the code from this guide as wp-content/mu-plugins/simple-contact-form.php. Then add a Shortcode block with [simple_contact_form] to a page. Messages are emailed to the site admin and saved under Messages.

Q3. Does WordPress 7 have a form block?

No. WordPress 7.1.3 has no form block in core. The experimental form blocks lived only in the Gutenberg plugin, and the team removed them in September 2026.

Q4. How do I send mail in WordPress without a plugin?

Call wp_mail() with the recipient, subject and message. For reliable delivery, connect it to an SMTP service with the phpmailer_init hook and add SPF and DKIM records for your domain.

Q5. Is a custom form safer than a form plugin?

It can be, because it has less code. It is only safe if it checks a nonce, sanitizes every field and escapes output. A popular plugin gets security fixes from its developer, while custom code depends on you.

Q6. Where are submissions from a custom form stored?

Wherever your code puts them. The form in this guide saves each one as a private post you can read under Messages. Without that step, the only copy is the email.

Yash Kapoor
Yash Kapoor

Yash Kapoor is the founder and WordPress expert at DevDiggers, where he builds WordPress and WooCommerce plugins for loyalty programs, point-of-sale systems, digital wallets and affiliate management. He writes about developer tools, site performance and the technical side of running a WordPress store. He draws on years of building and maintaining production plugin codebases.

Leave a Reply

Your email address will not be published. Required fields are marked *