{"id":7488,"date":"2015-01-30T15:21:09","date_gmt":"2015-01-30T20:21:09","guid":{"rendered":"https:\/\/docs.gravityforms.com\/documentation2\/"},"modified":"2025-03-27T16:53:23","modified_gmt":"2025-03-27T20:53:23","slug":"where-do-i-put-this-code","status":"publish","type":"post","link":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/","title":{"rendered":"Where Do I Put This Code?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-introduction\">Introduction<\/h2>\n\n\n\n<p>Depending on what code you are trying to add, and the complexity of the theme you are using, there can be a number of different places that code snippets can be added to extend your forms. This article covers most of the common options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-important\">Important!<\/h2>\n\n\n\n<p>Replacing or updating your theme can overwrite the theme directory in your site folder, which means modifications like these you may have made to files there will be lost. Always keep regular back-ups, consider using<a href=\"https:\/\/developer.wordpress.org\/themes\/advanced-topics\/child-themes\/\" target=\"_blank\" rel=\"noopener noreferrer\"> a child theme<\/a>, and check out some of the <a href=\"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/#h-third-party-plug-ins\">third party plugins<\/a> that provide safer alternatives for adding code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-css\">CSS<\/h2>\n\n\n\n<p>CSS code will typically look something like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: css; title: ; notranslate\" title=\"\">\nbody .gform_wrapper { border:1px solid red }\n<\/pre><\/div>\n\n\n<p>Please see <a href=\"https:\/\/docs.gravityforms.com\/where-to-put-your-custom-css\/\">this article<\/a> for placement options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-javascript-jquery\">JavaScript\/jQuery<\/h2>\n\n\n\n<p>Refer to <a href=\"https:\/\/docs.gravityforms.com\/adding-javascript-code-to-the-admin-side-of-your-site\/\">this<\/a> article for placement options when adding JavaScript to the admin side of your site and <a href=\"https:\/\/docs.gravityforms.com\/?p=42418\">this<\/a> article for adding JavaScript to the front end.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-php\">PHP<\/h2>\n\n\n\n<p>PHP code will typically look something like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nfunction gform_add_post_format( $entry ) {\n\n    $post_id = rgar( $entry, &#039;post_id&#039; );\n\n    if( !$post_id )\n        return;\n\n    wp_set_object_terms( $post_id, &#039;chat&#039;, &#039;post_format&#039; );\n\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-theme-s-functions-php-file\">Theme&#8217;s functions.php file<\/h3>\n\n\n\n<p>PHP snippets will almost always be pasted in your theme&#8217;s <em>functions.php<\/em> file, after any other existing code, or after the opening <strong>&lt;?php<\/strong> tag.<\/p>\n\n\n\n<p>There are a few things to be aware of when adding PHP snippets:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Your <em>functions.php<\/em> will already have an opening <strong>&lt;?php<\/strong> tag. If the snippet you are copying also has an opening PHP tag, be sure to remove it before pasting it into your <em>functions.php<\/em> file.<\/li>\n\n\n\n<li>If the PHP snippet you are copying has an opening and closing PHP tag inside the code itself, do not remove these. This simply means that the code is exiting &#8220;PHP mode&#8221; to output content directly to the screen.<\/li>\n\n\n\n<li>If you update your theme, you will need to add the snippet again. To avoid this situation, please use a <a href=\"https:\/\/developer.wordpress.org\/themes\/advanced-topics\/child-themes\/\">child theme<\/a>.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-third-party-plugins\">Third Party Plugins<\/h2>\n\n\n\n<p>Some enterprising WordPress developers have released third-party plugins to provide safer methods for adding code. Check out the <a href=\"https:\/\/wordpress.org\/plugins\/\">WordPress repository<\/a> to see what is available.<\/p>\n\n\n\n<p>Here is one that has seen large install numbers: <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\">Code Snippets Third Party Plugin<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/wordpress.org\/plugins\/pluginception\/\">Pluginception<\/a> is another option to consider. It allows you to easily create custom functionality plugins from your WordPress dashboard.<\/p>\n\n\n\n<p><em>\u200b<strong>Disclaimer<\/strong>: Third-party se<\/em>rvices, <em>plugins, or code snippets that are referenced by our Support documentation or in Support Team communications are provided as suggestions only. We do not evaluate, test or officially support third-party solutions. You are wholly responsible for determining if any suggestion given is sufficient to meet the functional, security, legal, ongoing cost and support needs of your project.<\/em><br><br><em><em><em>Feedback, feature, and integration requests, and other functionality ideas can be submitted at <\/em><\/em><\/em><a href=\"http:\/\/forms.roadmap.gravity.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/forms.roadmap.gravity.com\/<\/a><em><em><em>.<\/em><\/em><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will show you where you should typically place code that is shown in our documentation.<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_autodraft_ids":[],"_sb_is_suggestion_mode":false,"_sb_show_suggestion_boards":false,"_sb_show_comment_boards":false,"_sb_suggestion_history":"","_sb_update_block_changes":"","_is_real_time_mode":false,"_realtime_collaborators":"","footnotes":"","jetpack_post_was_ever_published":false,"cf_checklist_status":[]},"categories":[191],"tags":[16956,19364,19365,19366,19367],"class_list":["post-7488","post","type-post","status-publish","format-standard","hentry","category-knowledge-base","tag-javascript","tag-custom-code","tag-php","tag-css","tag-snippet","wpautop"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Where Do I Put This Code? - Gravity Forms Documentation<\/title>\n<meta name=\"description\" content=\"In this article, we will show you where you should typically place code that is shown in our documentation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Where Do I Put This Code?\" \/>\n<meta property=\"og:description\" content=\"In this article, we will show you where you should typically place code that is shown in our documentation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Gravity Forms Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-30T20:21:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-27T20:53:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2023\/08\/gf-docs-default-v3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"544\" \/>\n\t<meta property=\"og:image:height\" content=\"288\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Justin Pakes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gravityforms\" \/>\n<meta name=\"twitter:site\" content=\"@gravityforms\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Justin Pakes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/\"},\"author\":{\"name\":\"Justin Pakes\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/person\\\/8a88745ec2ee5bc1bb24eea8634bf376\"},\"headline\":\"Where Do I Put This Code?\",\"datePublished\":\"2015-01-30T20:21:09+00:00\",\"dateModified\":\"2025-03-27T20:53:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/\"},\"wordCount\":362,\"publisher\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#organization\"},\"keywords\":[\"javascript\",\"custom code\",\"php\",\"css\",\"snippet\"],\"articleSection\":[\"Knowledge Base\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/\",\"name\":\"Where Do I Put This Code? - Gravity Forms Documentation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#website\"},\"datePublished\":\"2015-01-30T20:21:09+00:00\",\"dateModified\":\"2025-03-27T20:53:23+00:00\",\"description\":\"In this article, we will show you where you should typically place code that is shown in our documentation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/where-do-i-put-this-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/docs.gravityforms.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Where Do I Put This Code?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#website\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/\",\"name\":\"Gravity Forms Documentation\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/docs.gravityforms.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#organization\",\"name\":\"Gravity Forms\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/gravity-forms-2020-logo-stacked.png\",\"contentUrl\":\"https:\\\/\\\/docs.gravityforms.com\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/gravity-forms-2020-logo-stacked.png\",\"width\":392,\"height\":515,\"caption\":\"Gravity Forms\"},\"image\":{\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/gravityforms\",\"http:\\\/\\\/@gravityforms.com\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/docs.gravityforms.com\\\/#\\\/schema\\\/person\\\/8a88745ec2ee5bc1bb24eea8634bf376\",\"name\":\"Justin Pakes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g\",\"caption\":\"Justin Pakes\"},\"url\":\"https:\\\/\\\/docs.gravityforms.com\\\/author\\\/pakes\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Where Do I Put This Code? - Gravity Forms Documentation","description":"In this article, we will show you where you should typically place code that is shown in our documentation.","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:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/","og_locale":"en_US","og_type":"article","og_title":"Where Do I Put This Code?","og_description":"In this article, we will show you where you should typically place code that is shown in our documentation.","og_url":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/","og_site_name":"Gravity Forms Documentation","article_published_time":"2015-01-30T20:21:09+00:00","article_modified_time":"2025-03-27T20:53:23+00:00","og_image":[{"width":544,"height":288,"url":"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2023\/08\/gf-docs-default-v3.png","type":"image\/png"}],"author":"Justin Pakes","twitter_card":"summary_large_image","twitter_creator":"@gravityforms","twitter_site":"@gravityforms","twitter_misc":{"Written by":"Justin Pakes","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/#article","isPartOf":{"@id":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/"},"author":{"name":"Justin Pakes","@id":"https:\/\/docs.gravityforms.com\/#\/schema\/person\/8a88745ec2ee5bc1bb24eea8634bf376"},"headline":"Where Do I Put This Code?","datePublished":"2015-01-30T20:21:09+00:00","dateModified":"2025-03-27T20:53:23+00:00","mainEntityOfPage":{"@id":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/"},"wordCount":362,"publisher":{"@id":"https:\/\/docs.gravityforms.com\/#organization"},"keywords":["javascript","custom code","php","css","snippet"],"articleSection":["Knowledge Base"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/","url":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/","name":"Where Do I Put This Code? - Gravity Forms Documentation","isPartOf":{"@id":"https:\/\/docs.gravityforms.com\/#website"},"datePublished":"2015-01-30T20:21:09+00:00","dateModified":"2025-03-27T20:53:23+00:00","description":"In this article, we will show you where you should typically place code that is shown in our documentation.","breadcrumb":{"@id":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/docs.gravityforms.com\/where-do-i-put-this-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/docs.gravityforms.com\/"},{"@type":"ListItem","position":2,"name":"Where Do I Put This Code?"}]},{"@type":"WebSite","@id":"https:\/\/docs.gravityforms.com\/#website","url":"https:\/\/docs.gravityforms.com\/","name":"Gravity Forms Documentation","description":"","publisher":{"@id":"https:\/\/docs.gravityforms.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/docs.gravityforms.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/docs.gravityforms.com\/#organization","name":"Gravity Forms","url":"https:\/\/docs.gravityforms.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/docs.gravityforms.com\/#\/schema\/logo\/image\/","url":"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2020\/01\/gravity-forms-2020-logo-stacked.png","contentUrl":"https:\/\/docs.gravityforms.com\/wp-content\/uploads\/2020\/01\/gravity-forms-2020-logo-stacked.png","width":392,"height":515,"caption":"Gravity Forms"},"image":{"@id":"https:\/\/docs.gravityforms.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/gravityforms","http:\/\/@gravityforms.com"]},{"@type":"Person","@id":"https:\/\/docs.gravityforms.com\/#\/schema\/person\/8a88745ec2ee5bc1bb24eea8634bf376","name":"Justin Pakes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/791cb5bec00c6dd4bec2e80cf4df9638297207d8f77890c96b6b483be434ecea?s=96&d=mm&r=g","caption":"Justin Pakes"},"url":"https:\/\/docs.gravityforms.com\/author\/pakes\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pdGaEa-1WM","_links":{"self":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts\/7488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/comments?post=7488"}],"version-history":[{"count":30,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts\/7488\/revisions"}],"predecessor-version":[{"id":42964,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/posts\/7488\/revisions\/42964"}],"wp:attachment":[{"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/media?parent=7488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/categories?post=7488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.gravityforms.com\/wp-json\/wp\/v2\/tags?post=7488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}