I want my users to be able to put a Contact Form 7 shortcode into a custom field in the Wordpress editor. I've created the custom field using ACF and I can pull the value onto the page, but when I try to include it in the shortcode, it comes back with a 404.
This code:
<?php echo do_shortcode(get_field('contact_form_shortcode')); ?>
Returns:
[contact-form-7 404 "Not Found"]
If I create a variable out of the value like this:
<?php
$formCode = get_field('contact_form_shortcode');
echo $formCode;
?>
The echo returns:
[contact-form-7 id="473" title="Learn More Form"]
But I get the same 404 after putting that value into the echo do_shortcode function list this:
<?php echo do_shortcode($formCode); ?>
What am I missing?
To do it With ACF pro plugin and without other extra plugins.
contact_form
)add the below code into your page loop:
<?php $posts = get_field('contact_form');
if( $posts ):
foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT)
$cf7_id= $p->ID;
echo do_shortcode( '[contact-form-7 id="'.$cf7_id.'" ]' );
endforeach;
endif; ?>