{"id":57397,"date":"2023-05-22T17:22:55","date_gmt":"2023-05-22T11:52:55","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57397"},"modified":"2023-05-30T17:34:06","modified_gmt":"2023-05-30T12:04:06","slug":"how-to-create-custom-location-dropdown-block-on-your-drupal-site","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-create-custom-location-dropdown-block-on-your-drupal-site\/","title":{"rendered":"How to Create Custom Location Dropdown Block On Your Drupal Site"},"content":{"rendered":"<h3>Here we are creating the Location Dropdown Block (Country-Region Dropdown) with the help of taxonomy terms.<\/h3>\n<h4><em><strong>Steps:-<\/strong><\/em><\/h4>\n<h4>First of all, We have to go on over Drupal Site and Create the Vocabulary Name &#8216;Location&#8217;:<\/h4>\n<p><em>structure\/taxonomy\/Location<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57381\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/first-1.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/first-1.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/first-1-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/first-1-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/first-1-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h4>Then Create Country as Parent Term And Region as Child Term accordingly :<\/h4>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57382\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-1-1.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-1-1.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-1-1-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-1-1-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-1-1-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57383\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-2-1.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-2-1.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-2-1-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-2-1-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/second-2-1-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h4 style=\"text-align: left;\">Create a Custom Module For the Location Dropdown Block (We can also use any Existing Custom\u00a0 Module For Location Dropdown Block):<\/h4>\n<p><em>\u00a0Create Custom Block File (PHP file):<\/em><\/p>\n<p><em>src\/Plugin\/Block\/LocationDropdownBlock.php<\/em><\/p>\n<p style=\"text-align: center;\"><strong>Here is the Example Code of .PHP file<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57388\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-1-2.png\" alt=\"\" width=\"850\" height=\"360\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-1-2.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-1-2-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-1-2-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-1-2-624x264.png 624w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57389\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-2.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-2.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-2-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-2-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-2-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57390\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-3.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-3.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-3-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-3-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/code1-3-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h4>Now we have to use any API to get the IP Address of the User:<\/h4>\n<p><em><strong>Free API to get the IP Address Of the User:<\/strong><\/em><\/p>\n<p>1. https:\/\/ipapi.co\/json<br \/>\n2 <a href=\"https:\/\/rapidapi.com\/ibrarasadbiz\/api\/ip-geo-location-find-ip-location-and-details\/\">.https:\/\/rapidapi.com\/ibrarasadbiz\/api\/ip-geo-location-find-ip-location-and-details\/<\/a><\/p>\n<p>3.<a href=\"https:\/\/rapidapi.com\/xakageminato\/api\/ip-geolocation-ipwhois-io\/-\" target=\"_blank\" rel=\"noopener\">https:\/\/rapidapi.com\/xakageminato\/api\/ip-geolocation-ipwhois-io\/-<\/a><\/p>\n<p><strong><em>Paid API to get the IP Address Of the User:<\/em><\/strong><\/p>\n<p><a href=\"https:\/\/developers.google.com\/maps\/documentation\/geolocation\/get-api-key\">https:\/\/developers.google.com\/maps\/documentation\/geolocation\/get-api-key<\/a><\/p>\n<p><strong><em>we are using free API :<\/em><\/strong>&#8211;<a href=\"https:\/\/ipapi.co\/json\" target=\"_blank\" rel=\"noopener\">https:\/\/ipapi.co\/json<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57384\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/third-api-img-1.png\" alt=\"\" width=\"850\" height=\"360\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/third-api-img-1.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/third-api-img-1-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/third-api-img-1-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/third-api-img-1-624x264.png 624w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h4>Create a Form :-<\/h4>\n<p><em>src\/Form\/DemoappLocationBlockForm.php:<\/em><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><strong>\u00a0Here is the Example Code of .PHP file<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57392\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code2-1.png\" alt=\"\" width=\"850\" height=\"360\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57393\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code2-2.png\" alt=\"\" width=\"850\" height=\"360\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57394\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code2-3.png\" alt=\"\" width=\"850\" height=\"360\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57395\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code2-4.png\" alt=\"\" width=\"850\" height=\"360\" \/><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57396\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/code2-5.png\" alt=\"\" width=\"850\" height=\"360\" \/><\/p>\n<p>&nbsp;<\/p>\n<h4>Next, Go to Your Drupal Site and Install the Location Dropdown Block:<\/h4>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57386\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/fourth-install-img-1.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/fourth-install-img-1.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/fourth-install-img-1-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/fourth-install-img-1-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/fourth-install-img-1-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h4>Place the Location Dropdown Block into the Header Region:<\/h4>\n<p><em>Go to structure\/block layout\/<\/em><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-57385\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/fifth-img-1.png\" alt=\"\" width=\"850\" height=\"360\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/fifth-img-1.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/fifth-img-1-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/fifth-img-1-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/fifth-img-1-624x264.png 624w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3>We can now see the location of the user as per region:<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-57387\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/last-img.png\" alt=\"\" width=\"625\" height=\"265\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/05\/last-img.png 850w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/last-img-300x127.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/last-img-768x325.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/05\/last-img-624x264.png 624w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>If you still have any questions regarding the topic, drop your comments down below.<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Here we are creating the Location Dropdown Block (Country-Region Dropdown) with the help of taxonomy terms. Steps:- First of all, We have to go on over Drupal Site and Create the Vocabulary Name &#8216;Location&#8217;: structure\/taxonomy\/Location &nbsp; Then Create Country as Parent Term And Region as Child Term accordingly : &nbsp; Create a Custom Module For [&hellip;]<\/p>\n","protected":false},"author":1528,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[3602],"tags":[4674,5248],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57397"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1528"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57397"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57397\/revisions"}],"predecessor-version":[{"id":57547,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57397\/revisions\/57547"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}