{"id":2133,"date":"2020-11-22T16:18:20","date_gmt":"2020-11-22T08:18:20","guid":{"rendered":"https:\/\/www.intelliwolf.com\/?p=2133"},"modified":"2022-04-11T14:06:42","modified_gmt":"2022-04-11T06:06:42","slug":"add-custom-class-to-astra-search-form","status":"publish","type":"post","link":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/","title":{"rendered":"How To Add A Custom Class To Astra Search Form"},"content":{"rendered":"\n

A friend had a question on how to add a custom class to the header search box in Astra that was too complex to answer in a Facebook post, so I'll put it here.<\/p>\n\n\n\n

Essentially, he wanted to add a class to the input field which already has the class \"search-field\".<\/p>\n\n\n\n

\"Code<\/figure><\/div>\n\n\n\n

The class he wanted to add is \"addsearch\".<\/p>\n\n\n\n

The simplest way to do this non-destructively with PHP is to add the following code to your child theme<\/a>:<\/p>\n\n\n\n

add_filter ('astra_get_search_form', 'add_custom_search_class');\nfunction add_custom_search_class($form) {\n  $class_position = strpos($form, 'search-field');\n\n  return substr_replace($form, 'addsearch ', $class_position, 0);\n}<\/code><\/pre>\n\n\n\n

This filter pulls in the html of the form as a string.<\/p>\n\n\n\n

It then looks through the html for the phrase \"search-field\" and returns the position of where it's located in the string.<\/p>\n\n\n\n

Finally, it puts \"addsearch \" before \"search-field\" and returns the html of the form.<\/p>\n\n\n\n

The space at the end of \"addsearch \" is intentional, so that we end up with class=\"addsearch search-field\"<\/em> as you can see below.<\/p>\n\n\n\n

\"Code<\/figure><\/div>\n\n\n\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

A friend had a question on how to add a custom class to the header search box in Astra that was too complex to answer in a Facebook post, so I’ll put it here. Essentially, he wanted to add a class to the input field which already has the class “search-field”. The class he wanted<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[19],"yoast_head":"\nHow To Add A Custom Class To Astra Search Form<\/title>\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.intelliwolf.com\/add-custom-class-to-astra-search-form\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Add A Custom Class To Astra Search Form\" \/>\n<meta property=\"og:description\" content=\"A friend had a question on how to add a custom class to the header search box in Astra that was too complex to answer in a Facebook post, so I'll put it here. Essentially, he wanted to add a class to the input field which already has the class "search-field". The class he wanted\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/\" \/>\n<meta property=\"og:site_name\" content=\"Intelliwolf\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-22T08:18:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-11T06:06:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01-600x179.png\" \/>\n<meta name=\"author\" content=\"Mike Haydon\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mike Haydon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/\"},\"author\":{\"name\":\"Mike Haydon\",\"@id\":\"https:\/\/www.intelliwolf.com\/#\/schema\/person\/7209e3ff14822e4d70d5f194a310f343\"},\"headline\":\"How To Add A Custom Class To Astra Search Form\",\"datePublished\":\"2020-11-22T08:18:20+00:00\",\"dateModified\":\"2022-04-11T06:06:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/\"},\"wordCount\":157,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.intelliwolf.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01-600x179.png\",\"keywords\":[\"Astra\"],\"articleSection\":[\"Theme Customization\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/\",\"url\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/\",\"name\":\"How To Add A Custom Class To Astra Search Form\",\"isPartOf\":{\"@id\":\"https:\/\/www.intelliwolf.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01-600x179.png\",\"datePublished\":\"2020-11-22T08:18:20+00:00\",\"dateModified\":\"2022-04-11T06:06:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage\",\"url\":\"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01.png\",\"contentUrl\":\"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01.png\",\"width\":642,\"height\":192},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.intelliwolf.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Theme Customization\",\"item\":\"https:\/\/www.intelliwolf.com\/category\/theme-customization\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How To Add A Custom Class To Astra Search Form\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.intelliwolf.com\/#website\",\"url\":\"https:\/\/www.intelliwolf.com\/\",\"name\":\"Intelliwolf\",\"description\":\"WordPress, Web Design & Coding Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.intelliwolf.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.intelliwolf.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.intelliwolf.com\/#organization\",\"name\":\"Intelliwolf\",\"url\":\"https:\/\/www.intelliwolf.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.intelliwolf.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/intelliwolf-logo-300t.png\",\"contentUrl\":\"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/intelliwolf-logo-300t.png\",\"width\":300,\"height\":100,\"caption\":\"Intelliwolf\"},\"image\":{\"@id\":\"https:\/\/www.intelliwolf.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.intelliwolf.com\/#\/schema\/person\/7209e3ff14822e4d70d5f194a310f343\",\"name\":\"Mike Haydon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.intelliwolf.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d5f4754fae310a04dede91d15e57c8a0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d5f4754fae310a04dede91d15e57c8a0?s=96&d=mm&r=g\",\"caption\":\"Mike Haydon\"},\"sameAs\":[\"https:\/\/intelliwolf.com\/about-mike-haydon\/\"]}]}<\/script>\n","yoast_head_json":{"title":"How To Add A Custom Class To Astra Search Form","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.intelliwolf.com\/add-custom-class-to-astra-search-form\/","og_locale":"en_US","og_type":"article","og_title":"How To Add A Custom Class To Astra Search Form","og_description":"A friend had a question on how to add a custom class to the header search box in Astra that was too complex to answer in a Facebook post, so I'll put it here. Essentially, he wanted to add a class to the input field which already has the class \"search-field\". The class he wanted","og_url":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/","og_site_name":"Intelliwolf","article_published_time":"2020-11-22T08:18:20+00:00","article_modified_time":"2022-04-11T06:06:42+00:00","og_image":[{"url":"https:\/\/intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01-600x179.png"}],"author":"Mike Haydon","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mike Haydon","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#article","isPartOf":{"@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/"},"author":{"name":"Mike Haydon","@id":"https:\/\/www.intelliwolf.com\/#\/schema\/person\/7209e3ff14822e4d70d5f194a310f343"},"headline":"How To Add A Custom Class To Astra Search Form","datePublished":"2020-11-22T08:18:20+00:00","dateModified":"2022-04-11T06:06:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/"},"wordCount":157,"commentCount":0,"publisher":{"@id":"https:\/\/www.intelliwolf.com\/#organization"},"image":{"@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage"},"thumbnailUrl":"https:\/\/intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01-600x179.png","keywords":["Astra"],"articleSection":["Theme Customization"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/","url":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/","name":"How To Add A Custom Class To Astra Search Form","isPartOf":{"@id":"https:\/\/www.intelliwolf.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage"},"image":{"@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage"},"thumbnailUrl":"https:\/\/intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01-600x179.png","datePublished":"2020-11-22T08:18:20+00:00","dateModified":"2022-04-11T06:06:42+00:00","breadcrumb":{"@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#primaryimage","url":"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01.png","contentUrl":"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/2020\/11\/2020-11-22-add-custom-class-astra-search-01.png","width":642,"height":192},{"@type":"BreadcrumbList","@id":"https:\/\/www.intelliwolf.com\/add-custom-class-to-astra-search-form\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.intelliwolf.com\/"},{"@type":"ListItem","position":2,"name":"Theme Customization","item":"https:\/\/www.intelliwolf.com\/category\/theme-customization\/"},{"@type":"ListItem","position":3,"name":"How To Add A Custom Class To Astra Search Form"}]},{"@type":"WebSite","@id":"https:\/\/www.intelliwolf.com\/#website","url":"https:\/\/www.intelliwolf.com\/","name":"Intelliwolf","description":"WordPress, Web Design & Coding Tutorials","publisher":{"@id":"https:\/\/www.intelliwolf.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.intelliwolf.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.intelliwolf.com\/#organization","name":"Intelliwolf","url":"https:\/\/www.intelliwolf.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.intelliwolf.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/intelliwolf-logo-300t.png","contentUrl":"https:\/\/www.intelliwolf.com\/wp-content\/uploads\/intelliwolf-logo-300t.png","width":300,"height":100,"caption":"Intelliwolf"},"image":{"@id":"https:\/\/www.intelliwolf.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.intelliwolf.com\/#\/schema\/person\/7209e3ff14822e4d70d5f194a310f343","name":"Mike Haydon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.intelliwolf.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d5f4754fae310a04dede91d15e57c8a0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5f4754fae310a04dede91d15e57c8a0?s=96&d=mm&r=g","caption":"Mike Haydon"},"sameAs":["https:\/\/intelliwolf.com\/about-mike-haydon\/"]}]}},"_links":{"self":[{"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/posts\/2133"}],"collection":[{"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/comments?post=2133"}],"version-history":[{"count":2,"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/posts\/2133\/revisions"}],"predecessor-version":[{"id":2138,"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/posts\/2133\/revisions\/2138"}],"wp:attachment":[{"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/media?parent=2133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/categories?post=2133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.intelliwolf.com\/wp-json\/wp\/v2\/tags?post=2133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}