{"id":1005,"date":"2025-03-24T14:28:15","date_gmt":"2025-03-24T14:28:15","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-to-allow-scripts-in-gd-custom-field-values\/"},"modified":"2025-04-03T15:24:36","modified_gmt":"2025-04-03T14:24:36","slug":"how-to-allow-scripts-in-gd-custom-field-values","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/tips-tricks-more\/how-to-allow-scripts-in-gd-custom-field-values\/","title":{"rendered":"How to allow scripts in GD Custom Field Values"},"content":{"rendered":"\n<p>GeoDirectory Custom Fields can be a powerful tool for using scripts that enhance the GD Single.<\/p>\n\n\n\n<p>In order to use scripts we recommend the use of an HTML custom field set to &#8216;Admin only&#8217;.&nbsp;<\/p>\n\n\n\n<p>Further, you will need to add this Code Snippet that will remove the automatic sanitization performed by GD.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/**\n * Skip sanitize based on field type.\n *\n * WARNING \u2013 Skipping sanitize routine for field values may result in a Cross-Site Scripting Attack (XSS) on your site.\n *\n * Skipping sanitize values may result in cross-site scripting (XSS) attack.\n *\/\nfunction gd_snippet_custom_skip_sanitize_field( $value, $gd_post, $custom_field, $post_id, $post, $update ) {\n\t\/\/ Fields to skip strip tags.\n\t$skip_strip_tags = array();\n\t$skip_strip_tags&#091;&#093; = &#039;my_custom_field&#039;; \/\/ field key - change this to match your key\n\n\n\tif ( in_array( $custom_field-&gt;htmlvar_name, $skip_strip_tags ) ) {\n\t\t$value = $gd_post&#091; $custom_field-&gt;htmlvar_name &#093;;\n\n\n\t\tif ( isset( $custom_field-&gt;data_type ) &amp;&amp; ( $custom_field-&gt;data_type == &#039;DECIMAL&#039; || $custom_field-&gt;data_type == &#039;INT&#039; ) &amp;&amp; $value === &#039;&#039; ) {\n\t\t\t$value = null;\n\t\t}\n\t}\n\treturn $value;\n}\nadd_filter( &#039;geodir_custom_field_value_html&#039;, &#039;gd_snippet_custom_skip_sanitize_field&#039;, 11, 6 );<\/code><\/pre>\n\n\n\n<p><br>Give it a try and let us know how it goes.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>GeoDirectory Custom Fields can be a powerful tool for using scripts that enhance the GD Single. In order to use scripts we recommend the use of an HTML custom field set to &#8216;Admin only&#8217;.&nbsp; Further, you will need to add this Code Snippet that will remove the automatic sanitization performed by GD. Give it a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,2],"class_list":["post-1005","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-uncategorized"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=1005"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1005\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=1005"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=1005"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=1005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}