{"id":16942,"date":"2021-04-08T08:50:03","date_gmt":"2021-04-08T12:50:03","guid":{"rendered":"https:\/\/www.gravityforms.com\/?p=16942"},"modified":"2026-03-24T16:38:02","modified_gmt":"2026-03-24T20:38:02","slug":"embed-forms-using-code","status":"publish","type":"post","link":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/","title":{"rendered":"How to Embed WordPress Forms Using Code"},"content":{"rendered":"\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20471\" src=\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png\" alt=\"Embed a Form\" width=\"1236\" height=\"824\" srcset=\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png 1236w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue-300x200.png 300w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue-1024x683.png 1024w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue-768x512.png 768w\" sizes=\"auto, (max-width: 1236px) 100vw, 1236px\" \/><br>\nEmbedding forms into your content is pretty easy using Gravity Forms&#8217; built-in support for <a href=\"https:\/\/docs.gravityforms.com\/adding-a-form-using-classic-editor\/\">WordPress Classic Editor<\/a> or <a href=\"https:\/\/docs.gravityforms.com\/adding-a-form-using-blocks\/\">Gutenberg.<\/a> You can even use the Form Widget, added to the WordPress Appearance Widgets menu, to embed a form into any of the WordPress widget areas.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>But&#8230; what if you want to embed the same form underneath the content on all of your blog posts? You can of course use the above to embed the form manually for each post, although that doesn&#8217;t sound like a smart way of achieving our goal, right?<\/p>\n\n\n\n<p>There must be a better way to make technology work for us, don&#8217;t you think?<\/p>\n\n\n\n<p>Well there is! We call it the <a href=\"https:\/\/docs.gravityforms.com\/adding-a-form-to-the-theme-file\/\">function call embedding method<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What?<\/h2>\n\n\n\n<p>It basically consists of two functions provided by Gravity Forms core that you can use to embed your form using code:<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.gravityforms.com\/adding-a-form-to-the-theme-file\/#function-call\" target=\"_blank\" rel=\"noopener noreferrer\">gravity_form()<\/a> &#8211; This is the main function, that takes care of displaying the form.<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.gravityforms.com\/gravity_form_enqueue_scripts\/\" target=\"_blank\" rel=\"noopener noreferrer\">gravity_form_enqueue_scripts()<\/a> &#8211; This function is a <strong>required <\/strong>companion, that will ask WordPress to enqueue the required CSS and JS files for the form.<\/p>\n\n\n\n<p>I will assume that you already know how to <a href=\"https:\/\/www.gravityforms.com\/how-to-create-a-newsletter-signup-form\/\" target=\"_blank\" rel=\"noopener noreferrer\">create and configure a Newsletter form<\/a>. Therefore I will focus this tutorial on using the above functions along with the WordPress filter <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/the_content\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">the_content<\/a> and <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/get_header\/\" target=\"_blank\" rel=\"noopener noreferrer\">get_header<\/a> hook.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing gravity_form() to call our form.<\/h2>\n\n\n\n<p>First, we need to know the id of our form. <strong>My Newsletter form has id 5<\/strong>. This will be the first parameter for the gravity_form() function call, and the only one that is <strong>required<\/strong>. So you could just use the following:<\/p>\n\n\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\ngravity_form( 5 );\n<\/pre>\n\n\n\n<p>But in this case I want also to enable ajax submission to avoid the page reloading when a visitor clicks the form button.<\/p>\n\n\n\n<p>The parameter to enable ajax submissions is the sixth parameter and <strong>another important parameter for this use case is the echo parameter <\/strong>&#8211; this last one we need to set to false to tell Gravity Forms to return the form instead of printing it directly to the screen.<\/p>\n\n\n\n<p>Therefore I will use <strong>default values for all the parameters except for the form id, ajax submission and echo<\/strong>, for which I will use 5, true and false respectively. My function call will look like this:<\/p>\n\n\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\ngravity_form( 5, true, true, false, false, true, false, false );\n<\/pre>\n\n\n\n<p>You can find more details about each parameter by checking the <a href=\"https:\/\/docs.gravityforms.com\/adding-a-form-to-the-theme-file\/#function-call\" target=\"_blank\" rel=\"noopener noreferrer\">documentation for the gravity_form() function call<\/a>.<\/p>\n\n\n\n<p>At this point we know already which function and parameters we will use to get the form.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing gravity_form_enqueue_scripts() to enqueue the required scripts.<\/h2>\n\n\n\n<p>Now we need to prepare the function that will ask WordPress to enqueue the required files for our form to be displayed and work as expected.<\/p>\n\n\n\n<p>gravity_form_enqueue_scripts() has only two parameters, the first one to specify the id of our form, and the second to make ajax submission enabled or not (disabled by default).<\/p>\n\n\n\n<p>We want to use ajax submission for our form, so we will use the two parameters, like this:<\/p>\n\n\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\ngravity_form_enqueue_scripts( 5, true );\n<\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using WordPress core get_header and the_content to trigger our functions.<\/h2>\n\n\n\n<p>At this point we have the Gravity Forms functions ready, the only thing left is to call them when needed to make the magic happen.<\/p>\n\n\n\n<p>We will use the WordPress core get_header hook to run the function to enqueue the files, this hook runs just before wp_head so it will ensure the files are already enqueued before Gravity Forms needs them.<\/p>\n\n\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\nfunction gf_enqueue_required_files() {\nGFCommon::log_debug( __METHOD__ . '(): running.' );\nif ( is_single() &amp;&amp; 'post' === get_post_type() ) { \/\/ Do it only for Posts.\ngravity_form_enqueue_scripts( 5, true );\n}\n}\nadd_action( 'get_header', 'gf_enqueue_required_files' );\n<\/pre>\n\n\n\n<p>The snippet has an if statement that will ensure it runs only for WordPress default posts.<\/p>\n\n\n\n<p>And finally we&#8217;re going to add our form at the end of our posts&#8217; content by using the following:<\/p>\n\n\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\nfunction gf_add_newsletter_form_after_post( $content ) {\nGFCommon::log_debug( __METHOD__ . '(): running.' );\n\/\/ Form added after the post content.\n$content .= gravity_form( 5, true, true, false, false, true, false, false );\nreturn $content;\n}\nadd_filter( 'the_content', 'gf_add_newsletter_form_after_post' );\n<\/pre>\n\n\n\n<p>That&#8217;s it! Once you have the above snippets added to your site, your form will be added <strong>dynamically<\/strong> after the content on each WordPress post you publish.<\/p>\n\n\n\n<p>And you know what? If you change your mind later, you don&#8217;t need to edit all your posts. As you&#8217;re embedding the form on the fly with the snippets, you can simply remove the snippets to stop the form from being added after your posts. Isn&#8217;t it great when machines do the work for you? ?<\/p>\n\n\n\n<p><em>Not a Gravity Forms customer yet? Get started with a <a href=\"https:\/\/www.gravityforms.com\/gravity-forms-demo\/\">free personalized demo<\/a> and test out all the features that Gravity Forms has to offer!<\/em><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<div class=\"alert_blue\">\n<figure><img decoding=\"async\" class=\"aligncenter size-full wp-image-15192\" src=\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1.png\" alt=\"Gravity Forms Newsletter\" width=\"80%\" height=\"auto\" srcset=\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1.png 2858w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1-300x101.png 300w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1-1024x345.png 1024w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1-768x259.png 768w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1-1536x518.png 1536w, https:\/\/www.gravityforms.com\/wp-content\/uploads\/2020\/06\/Gravity-Forms-Newsletter-1-2048x691.png 2048w\" sizes=\"(max-width: 2858px) 100vw, 2858px\" \/><\/figure><p><\/p>\n<p><strong>If you want to keep up-to-date with what&#8217;s happening on the blog sign up for the Gravity Forms newsletter!<\/strong><\/p>\n<\/div>\n\n\n<script>\nvar gform;gform||(document.addEventListener(\"gform_main_scripts_loaded\",function(){gform.scriptsLoaded=!0}),document.addEventListener(\"gform\/theme\/scripts_loaded\",function(){gform.themeScriptsLoaded=!0}),window.addEventListener(\"DOMContentLoaded\",function(){gform.domLoaded=!0}),gform={domLoaded:!1,scriptsLoaded:!1,themeScriptsLoaded:!1,isFormEditor:()=>\"function\"==typeof InitializeEditor,callIfLoaded:function(o){return!(!gform.domLoaded||!gform.scriptsLoaded||!gform.themeScriptsLoaded&&!gform.isFormEditor()||(gform.isFormEditor()&&console.warn(\"The use of gform.initializeOnLoaded() is deprecated in the form editor context and will be removed in Gravity Forms 3.1.\"),o(),0))},initializeOnLoaded:function(o){gform.callIfLoaded(o)||(document.addEventListener(\"gform_main_scripts_loaded\",()=>{gform.scriptsLoaded=!0,gform.callIfLoaded(o)}),document.addEventListener(\"gform\/theme\/scripts_loaded\",()=>{gform.themeScriptsLoaded=!0,gform.callIfLoaded(o)}),window.addEventListener(\"DOMContentLoaded\",()=>{gform.domLoaded=!0,gform.callIfLoaded(o)}))},hooks:{action:{},filter:{}},addAction:function(o,r,e,t){gform.addHook(\"action\",o,r,e,t)},addFilter:function(o,r,e,t){gform.addHook(\"filter\",o,r,e,t)},doAction:function(o){gform.doHook(\"action\",o,arguments)},applyFilters:function(o){return gform.doHook(\"filter\",o,arguments)},removeAction:function(o,r){gform.removeHook(\"action\",o,r)},removeFilter:function(o,r,e){gform.removeHook(\"filter\",o,r,e)},addHook:function(o,r,e,t,n){null==gform.hooks[o][r]&&(gform.hooks[o][r]=[]);var d=gform.hooks[o][r];null==n&&(n=r+\"_\"+d.length),gform.hooks[o][r].push({tag:n,callable:e,priority:t=null==t?10:t})},doHook:function(r,o,e){var t;if(e=Array.prototype.slice.call(e,1),null!=gform.hooks[r][o]&&((o=gform.hooks[r][o]).sort(function(o,r){return o.priority-r.priority}),o.forEach(function(o){\"function\"!=typeof(t=o.callable)&&(t=window[t]),\"action\"==r?t.apply(null,e):e[0]=t.apply(null,e)})),\"filter\"==r)return e[0]},removeHook:function(o,r,t,n){var e;null!=gform.hooks[o][r]&&(e=(e=gform.hooks[o][r]).filter(function(o,r,e){return!!(null!=n&&n!=o.tag||null!=t&&t!=o.priority)}),gform.hooks[o][r]=e)}});\n<\/script>\n\n                <div class='gf_browser_chrome gform_wrapper gravity-theme gform-theme--no-framework' data-form-theme='gravity-theme' data-form-index='0' id='gform_wrapper_83' >\n                        <div class='gform_heading'>\n\t\t\t\t\t\t\t<p class='gform_required_legend'>&quot;<span class=\"gfield_required gfield_required_asterisk\">*<\/span>&quot; indicates required fields<\/p>\n                        <\/div><form method='post' enctype='multipart\/form-data'  id='gform_83'  action='\/wp-json\/wp\/v2\/posts\/16942' data-formid='83' novalidate> \r\n <input type='hidden' class='gforms-pum' value='{\"closepopup\":false,\"closedelay\":0,\"openpopup\":false,\"openpopup_id\":0}' \/>\n                        <div class='gform-body gform_body'><div id='gform_fields_83' class='gform_fields top_label form_sublabel_below description_below validation_below'><div id=\"field_83_5\" class=\"gfield gfield--type-honeypot gform_validation_container field_sublabel_below gfield--has-description field_description_below field_validation_below gfield_visibility_visible\"  ><label class='gfield_label gform-field-label' for='input_83_5'>Company<\/label><div class='ginput_container'><input name='input_5' id='input_83_5' type='text' value='' autocomplete='new-password'\/><\/div><div class='gfield_description' id='gfield_description_83_5'>This field is for validation purposes and should be left unchanged.<\/div><\/div><fieldset id=\"field_83_2\" class=\"gfield gfield--type-email gfield--input-type-email gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible\"  ><legend class='gfield_label gform-field-label gfield_label_before_complex' >Email<span class=\"gfield_required\"><span class=\"gfield_required gfield_required_asterisk\">*<\/span><\/span><\/legend><div class='ginput_complex ginput_container ginput_container_email gform-grid-row' id='input_83_2_container'>\n                                <span id='input_83_2_1_container' class='ginput_left gform-grid-col gform-grid-col--size-auto'>\n                                    <input class='' type='email' name='input_2' id='input_83_2' value=''    aria-required=\"true\" aria-invalid=\"false\"  \/>\n                                    <label for='input_83_2' class='gform-field-label gform-field-label--type-sub '>Enter Email<\/label>\n                                <\/span>\n                                <span id='input_83_2_2_container' class='ginput_right gform-grid-col gform-grid-col--size-auto'>\n                                    <input class='' type='email' name='input_2_2' id='input_83_2_2' value=''    aria-required=\"true\" aria-invalid=\"false\"  \/>\n                                    <label for='input_83_2_2' class='gform-field-label gform-field-label--type-sub '>Confirm Email<\/label>\n                                <\/span>\n                                <div class='gf_clear gf_clear_complex'><\/div>\n                            <\/div><\/fieldset><fieldset id=\"field_83_3\" class=\"gfield gfield--type-checkbox gfield--type-choice gfield--input-type-checkbox gfield_contains_required field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible\"  ><legend class='gfield_label gform-field-label gfield_label_before_complex' >Privacy<span class=\"gfield_required\"><span class=\"gfield_required gfield_required_asterisk\">*<\/span><\/span><\/legend><div class='ginput_container ginput_container_checkbox'><div class='gfield_checkbox ' id='input_83_3'><div class='gchoice gchoice_83_3_1'>\n\t\t\t\t\t\t\t\t<input class='gfield-choice-input' name='input_3.1' type='checkbox'  value='I agree with the storage and handling of my data by this website. - &lt;a target=&quot;_blank&quot; href=&quot;https:\/\/www.gravityforms.com\/privacy\/&quot; rel=&quot;noopener noreferrer&quot;&gt;Privacy Policy&lt;\/a&gt; &lt;abbr class=&quot;wpgdprc-required&quot; title=&quot;You need to accept this checkbox.&quot;&gt;*&lt;\/abbr&gt;'  id='choice_83_3_1'   \/>\n\t\t\t\t\t\t\t\t<label for='choice_83_3_1' id='label_83_3_1' class='gform-field-label gform-field-label--type-inline'>I agree with the storage and handling of my data by this website. - <a target=\"_blank\" href=\"https:\/\/www.gravityforms.com\/privacy\/\" rel=\"noopener noreferrer\">Privacy Policy<\/a> <abbr class=\"wpgdprc-required\" title=\"You need to accept this checkbox.\">*<\/abbr><\/label>\n\t\t\t\t\t\t\t<\/div><\/div><\/div><\/fieldset><div id=\"field_83_4\" class=\"gfield gfield--type-captcha gfield--input-type-captcha field_sublabel_below gfield--no-description field_description_below field_validation_below gfield_visibility_visible\"  ><label class='gfield_label gform-field-label' for='input_83_4'>CAPTCHA<\/label><div id='input_83_4' class='ginput_container ginput_recaptcha' data-sitekey='6LdxcbcqAAAAAHh5N4RW6tt2QeBFwHLDw3eYgN_j'  data-theme='light' data-tabindex='0'  data-badge=''><\/div><\/div><\/div><\/div>\n        <div class='gform-footer gform_footer top_label'> <input type='submit' id='gform_submit_button_83' class='gform_button button' onclick='gform.submission.handleButtonClick(this);' data-submission-type='submit' value='Keep me up to date!'  \/> <input type='hidden' class='gform_hidden' name='gform_submission_speeds' value='{&quot;pages&quot;:[]}' \/>\n            <input type='hidden' class='gform_hidden' name='gform_submission_method' data-js='gform_submission_method_83' value='postback' \/>\n            <input type='hidden' class='gform_hidden' name='gform_theme' data-js='gform_theme_83' id='gform_theme_83' value='gravity-theme' \/>\n            <input type='hidden' class='gform_hidden' name='gform_style_settings' data-js='gform_style_settings_83' id='gform_style_settings_83' value='[]' \/>\n            <input type='hidden' class='gform_hidden' name='is_submit_83' value='1' \/>\n            <input type='hidden' class='gform_hidden' name='gform_submit' value='83' \/>\n            \n            <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' \/>\n            <input type='hidden' class='gform_hidden' name='state_83' value='WyJbXSIsIjE2YTM4MzNjZDEzMDZiOGNmNmNkZWZkNTc0ZTJkOWViIl0=' \/>\n            <input type='hidden' autocomplete='off' class='gform_hidden' name='gform_target_page_number_83' id='gform_target_page_number_83' value='0' \/>\n            <input type='hidden' autocomplete='off' class='gform_hidden' name='gform_source_page_number_83' id='gform_source_page_number_83' value='1' \/>\n            <input type='hidden' name='gform_field_values' value='' \/>\n            \n        <\/div>\n                        <\/form>\n                        <\/div><script>\ngform.initializeOnLoaded( function() {gformInitSpinner( 83, 'https:\/\/www.gravityforms.com\/wp-content\/plugins\/gravityforms\/images\/spinner.svg', true );jQuery('#gform_ajax_frame_83').on('load',function(){var contents = jQuery(this).contents().find('*').html();var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;if(!is_postback){return;}var form_content = jQuery(this).contents().find('#gform_wrapper_83');var is_confirmation = jQuery(this).contents().find('#gform_confirmation_wrapper_83').length > 0;var is_redirect = contents.indexOf('gformRedirect(){') >= 0;var is_form = form_content.length > 0 && ! is_redirect && ! is_confirmation;var mt = parseInt(jQuery('html').css('margin-top'), 10) + parseInt(jQuery('body').css('margin-top'), 10) + 100;if(is_form){jQuery('#gform_wrapper_83').html(form_content.html());if(form_content.hasClass('gform_validation_error')){jQuery('#gform_wrapper_83').addClass('gform_validation_error');} else {jQuery('#gform_wrapper_83').removeClass('gform_validation_error');}setTimeout( function() { \/* delay the scroll by 50 milliseconds to fix a bug in chrome *\/  }, 50 );if(window['gformInitDatepicker']) {gformInitDatepicker();}if(window['gformInitPriceFields']) {gformInitPriceFields();}var current_page = jQuery('#gform_source_page_number_83').val();gformInitSpinner( 83, 'https:\/\/www.gravityforms.com\/wp-content\/plugins\/gravityforms\/images\/spinner.svg', true );jQuery(document).trigger('gform_page_loaded', [83, current_page]);window['gf_submitting_83'] = false;}else if(!is_redirect){var confirmation_content = jQuery(this).contents().find('.GF_AJAX_POSTBACK').html();if(!confirmation_content){confirmation_content = contents;}jQuery('#gform_wrapper_83').replaceWith(confirmation_content);jQuery(document).trigger('gform_confirmation_loaded', [83]);window['gf_submitting_83'] = false;wp.a11y.speak(jQuery('#gform_confirmation_message_83').text());}else{jQuery('#gform_83').append(contents);if(window['gformRedirect']) {gformRedirect();}}jQuery(document).trigger(\"gform_pre_post_render\", [{ formId: \"83\", currentPage: \"current_page\", abort: function() { this.preventDefault(); } }]);        if (event && event.defaultPrevented) {                return;        }        const gformWrapperDiv = document.getElementById( \"gform_wrapper_83\" );        if ( gformWrapperDiv ) {            const visibilitySpan = document.createElement( \"span\" );            visibilitySpan.id = \"gform_visibility_test_83\";            gformWrapperDiv.insertAdjacentElement( \"afterend\", visibilitySpan );        }        const visibilityTestDiv = document.getElementById( \"gform_visibility_test_83\" );        let postRenderFired = false;        function triggerPostRender() {            if ( postRenderFired ) {                return;            }            postRenderFired = true;            gform.core.triggerPostRenderEvents( 83, current_page );            if ( visibilityTestDiv ) {                visibilityTestDiv.parentNode.removeChild( visibilityTestDiv );            }        }        function debounce( func, wait, immediate ) {            var timeout;            return function() {                var context = this, args = arguments;                var later = function() {                    timeout = null;                    if ( !immediate ) func.apply( context, args );                };                var callNow = immediate && !timeout;                clearTimeout( timeout );                timeout = setTimeout( later, wait );                if ( callNow ) func.apply( context, args );            };        }        const debouncedTriggerPostRender = debounce( function() {            triggerPostRender();        }, 200 );        if ( visibilityTestDiv && visibilityTestDiv.offsetParent === null ) {            const observer = new MutationObserver( ( mutations ) => {                mutations.forEach( ( mutation ) => {                    if ( mutation.type === 'attributes' && visibilityTestDiv.offsetParent !== null ) {                        debouncedTriggerPostRender();                        observer.disconnect();                    }                });            });            observer.observe( document.body, {                attributes: true,                childList: false,                subtree: true,                attributeFilter: [ 'style', 'class' ],            });        } else {            triggerPostRender();        }    } );} );\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"<p>Do you want to embed the same form on multiple pages or posts on your site? No problem! Find out how to automate the process by adding some useful snippets to your WordPress website.<\/p>\n","protected":false},"author":83394,"featured_media":20471,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,10458,221],"tags":[10160],"class_list":["post-16942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-technical","category-tutorials","tag-embed-forms","wpautop"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.1 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Embed WordPress Forms Using Code - Gravity Forms<\/title>\n<meta name=\"description\" content=\"Want to embed the same form on multiple pages or posts? Find out how to simplify the process by adding some useful snippets to your website.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Embed WordPress Forms Using Code\" \/>\n<meta property=\"og:description\" content=\"Want to embed the same form on multiple pages or posts? Find out how to simplify the process by adding some useful snippets to your website.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Gravity Forms\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GravityForms\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-08T12:50:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-24T20:38:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1236\" \/>\n\t<meta property=\"og:image:height\" content=\"824\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Samuel Aguilera\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sacom\" \/>\n<meta name=\"twitter:site\" content=\"@GravityForms\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Samuel Aguilera\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\"},\"author\":{\"name\":\"Samuel Aguilera\",\"@id\":\"https:\/\/www.gravityforms.com\/#\/schema\/person\/cee6a1b2cfd4d1afd4fd68d836557621\"},\"headline\":\"How to Embed WordPress Forms Using Code\",\"datePublished\":\"2021-04-08T12:50:03+00:00\",\"dateModified\":\"2026-03-24T20:38:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\"},\"wordCount\":854,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.gravityforms.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png\",\"keywords\":[\"embed forms\"],\"articleSection\":[\"Blog\",\"Technical\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\",\"url\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\",\"name\":\"How to Embed WordPress Forms Using Code - Gravity Forms\",\"isPartOf\":{\"@id\":\"https:\/\/www.gravityforms.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png\",\"datePublished\":\"2021-04-08T12:50:03+00:00\",\"dateModified\":\"2026-03-24T20:38:02+00:00\",\"description\":\"Want to embed the same form on multiple pages or posts? Find out how to simplify the process by adding some useful snippets to your website.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage\",\"url\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png\",\"contentUrl\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png\",\"width\":1236,\"height\":824,\"caption\":\"Embed a Form\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Gravity Forms\",\"item\":\"https:\/\/www.gravityforms.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\/\/www.gravityforms.com\/category\/tutorials\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Embed WordPress Forms Using Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.gravityforms.com\/#website\",\"url\":\"https:\/\/www.gravityforms.com\/\",\"name\":\"Gravity Forms\",\"description\":\"WordPress Contact Forms\",\"publisher\":{\"@id\":\"https:\/\/www.gravityforms.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.gravityforms.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.gravityforms.com\/#organization\",\"name\":\"Gravity Forms\",\"url\":\"https:\/\/www.gravityforms.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gravityforms.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/09\/gravity-forms-logo-horizontal-744.png\",\"contentUrl\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/09\/gravity-forms-logo-horizontal-744.png\",\"width\":774,\"height\":400,\"caption\":\"Gravity Forms\"},\"image\":{\"@id\":\"https:\/\/www.gravityforms.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/GravityForms\",\"https:\/\/x.com\/GravityForms\",\"https:\/\/www.instagram.com\/gravityforms\/\",\"https:\/\/www.linkedin.com\/company\/gravityforms\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.gravityforms.com\/#\/schema\/person\/cee6a1b2cfd4d1afd4fd68d836557621\",\"name\":\"Samuel Aguilera\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/1eecc0ea9f7b55b6a0d0e9c0e0cbb45c7f99261e95741a1ea6ca7b395b580e58?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1eecc0ea9f7b55b6a0d0e9c0e0cbb45c7f99261e95741a1ea6ca7b395b580e58?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1eecc0ea9f7b55b6a0d0e9c0e0cbb45c7f99261e95741a1ea6ca7b395b580e58?s=96&d=mm&r=g\",\"caption\":\"Samuel Aguilera\"},\"sameAs\":[\"https:\/\/x.com\/sacom\"],\"url\":\"https:\/\/www.gravityforms.com\/author\/sacom\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Embed WordPress Forms Using Code - Gravity Forms","description":"Want to embed the same form on multiple pages or posts? Find out how to simplify the process by adding some useful snippets to your website.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/","og_locale":"en_US","og_type":"article","og_title":"How to Embed WordPress Forms Using Code","og_description":"Want to embed the same form on multiple pages or posts? Find out how to simplify the process by adding some useful snippets to your website.","og_url":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/","og_site_name":"Gravity Forms","article_publisher":"https:\/\/www.facebook.com\/GravityForms","article_published_time":"2021-04-08T12:50:03+00:00","article_modified_time":"2026-03-24T20:38:02+00:00","og_image":[{"width":1236,"height":824,"url":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png","type":"image\/png"}],"author":"Samuel Aguilera","twitter_card":"summary_large_image","twitter_creator":"@sacom","twitter_site":"@GravityForms","twitter_misc":{"Written by":"Samuel Aguilera","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#article","isPartOf":{"@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/"},"author":{"name":"Samuel Aguilera","@id":"https:\/\/www.gravityforms.com\/#\/schema\/person\/cee6a1b2cfd4d1afd4fd68d836557621"},"headline":"How to Embed WordPress Forms Using Code","datePublished":"2021-04-08T12:50:03+00:00","dateModified":"2026-03-24T20:38:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/"},"wordCount":854,"commentCount":0,"publisher":{"@id":"https:\/\/www.gravityforms.com\/#organization"},"image":{"@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage"},"thumbnailUrl":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png","keywords":["embed forms"],"articleSection":["Blog","Technical","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/","url":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/","name":"How to Embed WordPress Forms Using Code - Gravity Forms","isPartOf":{"@id":"https:\/\/www.gravityforms.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage"},"image":{"@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage"},"thumbnailUrl":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png","datePublished":"2021-04-08T12:50:03+00:00","dateModified":"2026-03-24T20:38:02+00:00","description":"Want to embed the same form on multiple pages or posts? Find out how to simplify the process by adding some useful snippets to your website.","breadcrumb":{"@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#primaryimage","url":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png","contentUrl":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/04\/Blog-Form-with-Save-and-Continue.png","width":1236,"height":824,"caption":"Embed a Form"},{"@type":"BreadcrumbList","@id":"https:\/\/www.gravityforms.com\/blog\/embed-forms-using-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Gravity Forms","item":"https:\/\/www.gravityforms.com\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/www.gravityforms.com\/category\/tutorials\/"},{"@type":"ListItem","position":3,"name":"How to Embed WordPress Forms Using Code"}]},{"@type":"WebSite","@id":"https:\/\/www.gravityforms.com\/#website","url":"https:\/\/www.gravityforms.com\/","name":"Gravity Forms","description":"WordPress Contact Forms","publisher":{"@id":"https:\/\/www.gravityforms.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.gravityforms.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.gravityforms.com\/#organization","name":"Gravity Forms","url":"https:\/\/www.gravityforms.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gravityforms.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/09\/gravity-forms-logo-horizontal-744.png","contentUrl":"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2021\/09\/gravity-forms-logo-horizontal-744.png","width":774,"height":400,"caption":"Gravity Forms"},"image":{"@id":"https:\/\/www.gravityforms.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GravityForms","https:\/\/x.com\/GravityForms","https:\/\/www.instagram.com\/gravityforms\/","https:\/\/www.linkedin.com\/company\/gravityforms\/"]},{"@type":"Person","@id":"https:\/\/www.gravityforms.com\/#\/schema\/person\/cee6a1b2cfd4d1afd4fd68d836557621","name":"Samuel Aguilera","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1eecc0ea9f7b55b6a0d0e9c0e0cbb45c7f99261e95741a1ea6ca7b395b580e58?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1eecc0ea9f7b55b6a0d0e9c0e0cbb45c7f99261e95741a1ea6ca7b395b580e58?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1eecc0ea9f7b55b6a0d0e9c0e0cbb45c7f99261e95741a1ea6ca7b395b580e58?s=96&d=mm&r=g","caption":"Samuel Aguilera"},"sameAs":["https:\/\/x.com\/sacom"],"url":"https:\/\/www.gravityforms.com\/author\/sacom\/"}]}},"_links":{"self":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts\/16942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/users\/83394"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/comments?post=16942"}],"version-history":[{"count":2,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts\/16942\/revisions"}],"predecessor-version":[{"id":38894,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts\/16942\/revisions\/38894"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/media\/20471"}],"wp:attachment":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/media?parent=16942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/categories?post=16942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/tags?post=16942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}