Home Forums Front-end Issues Error when creating new post


Error when creating new post

  • I’m using acf_form() to create new posts on the front end. The form displays correctly and the post get created, but when the user clicks the “create new post button” I get the following error message, even tho the post was created:

    Warning: Cannot modify header information – headers already sent by (output started at /home2/mcrbr/public_html/dirtylooks/teste/wp-content/themes/Frank_v42/template_form.php:1) in /home2/mcrbr/public_html/dirtylooks/teste/wp-includes/pluggable.php on line 1121

    Does anyone know how to fix it?

  • The error appears when a page is trying to redirect to another but there has already been content outputted to the current page, for example:

    /* This will give an error. Note the output
     * above, which is before the header() call */

    The “html” tag has already been output so the page will error when trying to redirect. Check if this is happening at all in your code

  • Thanks for the reply!

    I’ve checked the code and haven’t found anything like that, i’ve even removed any code that weren’t related to the form and nothing changes.

    Here’s the code I’m using:

    <?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(array(
    	  'post_id'	=> 'new',
    	  'field_groups'	=> array( 123 ),
    	  'submit_value'	=> 'Create a new event'
    	)); ?>
          <?php endwhile; ?>
        </div><!-- #content -->
      </div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  • Hi,

    I have a very similar issue. Did you manage to solve this?

    My theme/form works fine on my local wamp instalation but when I install it on a live wp site it displays a very similar error to yours whenever I try to post.

    Have you managed to fix this since your last reply? If you or anyone could share any light into this I would appreciate it.


  • Hi!

    I’m sorry to say, but I did not manage to solve this, I’ve done a lot of testing, but it kept giving the same error no matter what.

  • check if you have ANY blank spaces before your code in template_form.php and remove them. Also worth checking all your other files index.php, header.php for blank spaces before (and after) code. It’s a common cause for this error.

    If it doesn’t, try putting <?php acf_form_head(); ?> in your header.php instead (before any code and without any spaces before as I mentioned above)

    Hope this helps.

  • What worked for me was adding <?php acf_form_head(); ?> BEFORE <?php get_header(); ?> at the top of the page template.

  • I was having a lot of trouble with ‘headers already sent’ in an elaborately coded theme.

    Solution that goes in functions.php:

    add_action( 'init', 'brandpage_form_head' );
    function brandpage_form_head(){

    This will add it on every page, you could add an if statement to just get it just on your form page.

  • Moving acf_form_head() before get_header() as JustinCase suggested solved this problem for me.

  • I was having the same problem. Here’s the code snippet that worked for me to solve it:

    add_action( 'wp_head', 'clb_add_acf_form_functionality', 2);
     function clb_add_acf_form_functionality() {
  • add_action( 'init', 'brandpage_form_head' );
    function brandpage_form_head(){

    This solved it for me, thank you a lot!

  • This solved it for me, thank you a lot!

  • add_action( 'init', 'brandpage_form_head' );
    function brandpage_form_head(){

    This solved it for me, thank you a lot!

Viewing 13 posts - 1 through 13 (of 13 total)

The topic ‘Error when creating new post’ is closed to new replies.