- This topic has 7 replies, 3 voices, and was last updated 6 years ago by Tom.
-
AuthorPosts
-
March 2, 2016 at 12:10 am #176526Oleg
Hello!
I use plugin Advansed Custom Fields. I want to create frontend form, but I do not want to change the template files. It is necessary to add a function:acf_form_head();
to the beginning of page, for example:
<?php /** * The template for displaying all pages. * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package GeneratePress */ acf_form_head(); get_header(); ?> <div id="primary" <?php generate_content_class();?>> <main id="main" <?php generate_main_class(); ?>> <?php do_action('generate_before_main_content'); ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'page' ); ?> <?php // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || '0' != get_comments_number() ) : ?> <div class="comments-area"> <?php comments_template(); ?> </div> <?php endif; ?> <?php endwhile; // end of the loop. ?> <?php do_action('generate_after_main_content'); ?> </main><!-- #main --> </div><!-- #primary --> <?php do_action('generate_sidebars'); get_footer();
Here is the documentation on this page: http://www.advancedcustomfields.com/resources/create-a-front-end-form/.
My question is: is it possible to add this feature with the hooks? I tried to insert, but it is not working properly.
March 2, 2016 at 12:09 pm #176628TomLead DeveloperLead DeveloperNot sure if it will work, but you can try it in the “Above Header” hook like this:
<?php acf_form_head(); ?>
Make sure to check “Execute PHP”.
March 2, 2016 at 12:24 pm #176636OlegThis function works, but is not entirely correct. Maybe there is another way?
March 2, 2016 at 11:40 pm #176726TomLead DeveloperLead DeveloperHmm I’m not sure – I don’t have any experience with the plugin.
You may need to do it as they say I’m afraid.
April 13, 2018 at 3:01 am #549186TomášHi Tom,
amazing theme! If you could just add one more hook into GP premium, it would be amazing!
This hook should be something like “Before header HTML”.
This is beginning of your code in header.php
<?php /** * The template for displaying the header. * * @package GeneratePress */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } ------ HERE SHOULD BE THE EXTRA HOOK ------ ?><!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <link rel="profile" href="http://gmpg.org/xfn/11"> <?php wp_head(); ?> </head>
If you will create one more hook in the position marked as “—— HERE SHOULD BE THE EXTRA HOOK ——“, you will enable the front-end posting feature with Advanced Custom Fields plugin, because that’s exactly the place, where should “acf_form_head();” function be placed.
Thanks in advance!
April 13, 2018 at 9:44 am #549629TomLead DeveloperLead DeveloperAccording to their docs (https://www.advancedcustomfields.com/resources/acf_form_head/), you should be able to place that in the Before Header or wp_head hook 🙂
April 13, 2018 at 10:02 am #549652TomášWhen I place it inside one or the other hook, after form is submitted it returns the “Headers already sent” error.
I did already give it a try, that is why I asked you to add the extra hook.
Also according to their docs, they say:
This function must be placed before any HTML has been created…
If you won’t add the hook, I’ll understand. I’m using currently a workaround with child theme, where I copy the original header.php, it’s not so super important update, I just thought it will be appreciated also by other ACF users. 😉
April 13, 2018 at 8:59 pm #549975TomLead DeveloperLead DeveloperIt might be worth contacting them directly and asking. By HTML, do they mean before the actual
<html>
element? If so, I will definitely consider it 🙂 -
AuthorPosts
- You must be logged in to reply to this topic.