Overview

This article will cover how to create a form on the front end of your website to edit or create a new post.

The functions acf_form() and acf_form_head() allow you to create a form to edit a page / post. Both functions are required in a template for the editing and saving behaviors to work correctly.

Functions

acf_form_head()

This function registers the scripts / styles needed for the form (please note the admin styles may interfere with your template styles) and processes the $_POST data when the form is submitted.

acf_form()

This function creates the HTML for the form. you can pass an array of options to customize your form. Please read the complete acf_form() documentation to learn more about available parameters and usage

Usage

  1. Place the acf_form_head() function at the very top of your template file. it is important that this function is placed before any html is rendered.
  2. Place the acf_form() function where you want the form to appear.
<?php acf_form_head(); ?>
<?php get_header(); ?>
 
	<div id="primary">
		<div id="content" role="main">
 
			<?php /* The loop */ ?>
			<?php while ( have_posts() ) : the_post(); ?>
 
				<?php acf_form(); ?>
 
			<?php endwhile; ?>
 
		</div><!-- #content -->
	</div><!-- #primary -->
 
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Notes

Using the acf_form() function will also include admin css & js files which may conflict with your website.
You can prevent the WP admin styles from loading by including this code in your functions.php file:

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
 
function my_deregister_styles() {
	wp_deregister_style( 'wp-admin' );
}