get_search_form() and aria_label

The question:

How do you pass the aria_label parameter to get_search_form()?

I can’t seem to pass the ‘aria_label’ parameter to get_search_form() in the correct way and can’t find any examples. Lots with the first parameter ‘echo’ which works as in the documentation, but nothing I’ve tried for aria_label has made the search form add aria labels.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You can pass an array of attributes with aria_label attribute in it.
Try this:

get_search_form(array('aria_label' => 'search-form'));

This function gets a form from searchform.php by default and if you have this file in your theme and aria-label still missing, you need to check the code in this file. Sometimes developers do not include an option to set an aria-label.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment