Add search box into navigation

Using Sydney theme for our website.
Need to add search bar next to navigation.
Have created Sydney child theme.
Please guide.

Hi Magna,

Please the instruction on this thread and let me know how it goes.


Dear Awan,

Thank you for your reply.
Do I need to copy this below code at the top or bottom of functions.php page?
/* BEGIN */

add_filter(‘wp_nav_menu_items’,’search_box_function’, 10, 2);
function search_box_function( $nav, $args ) {
if( $args->theme_location == ‘primary’ )
return $nav.”<li class=’menu-header-search’><form action=’’ id=’searchform’ method=’get’><input type=’text’ name=’s’ id=’s’ placeholder=’Pesquisar…’></form>“;

return $nav;

/* END */

Your help will be appreciated.

Add it to the bottom of your functions.php file

Unsure what I am doing wrong but this is what I followed

This is the error I am getting

As I am new in this process. Your guidance will be appreciated.

Looks like there is any invalid character produced when you paste the code to your functions.php, please try the code in here instead.

I suggest you to edit your PHP file through the FTP access or from the file manager of your cpanel.

Thank you for your feedback.
a) Should the parent php file be edited or the child?
b) As you advised before I will paste the new code (as below) at the end of the function.php file is that right?

add_filter(‘wp_nav_menu_items’, ‘search_box_function’, 10, 2);
function search_box_function( $nav, $args ) {
if( $args->theme_location == ‘primary’ )
return $nav."<li class=‘menu-header-search’><form action=‘YOUR_SITE_URL’ id=‘searchform’ method=‘get’><input type=‘text’ name=‘s’ id=‘s’ placeholder=‘Pesquisar…’></form>";

return $nav;


Please edit the functions.php file in the child theme and make sure you activate the child theme after you finish on editing the file.

yes, put the code in the bottom of functions.php file and please use my code in instead.


Following your instruction, added code but,
The search box does not function.

Kindly help

Waiting for help.
Please respond.

Hi Magna,

Sorry for the delays. Could you please to post the URL of your site? or if its private, you can send your URL to awan.rimbawan101 at gmail

Hello Awan,

Just emailed you the link, thank you.
Appreciate, you always take time to reply


The script in above is working, but the problem is because you didn’t change the YOUR_SITE_URL on the script :smiley:

HEllo Awan,

Thank you for your feedback. How can the url be changed?
Please advise.


Please take a look on this custom code below:

add_filter('wp_nav_menu_items', 'search_box_function', 10, 2);
function search_box_function( $nav, $args ) {
	if( $args->theme_location == 'primary' )
	return $nav."<li class='menu-header-search'><form action='YOUR_SITE_URL' id='searchform' method='get'><input type='text' name='s' id='s' placeholder='Pesquisar…'></form>";

	return $nav;

from the code in above , all you need is just to change the YOUR_SITE_URL with your own site.

Dear, you know our team is not good with coding!!!
Can you teach us where to cut and paste this code?

We are not good with this coding, sorry for being honest.
Can you tell us where to copy and paste this code?


You already implement the custom code in above but there’s something missing with the code you’ve paste.

Please open functions.php file and change YOUR_SITE_URL with your site URL.

We added the url into child theme->functions->my site url
But when we input a search string. we still get the following page:
Oops! That page can’t be found.
It looks like nothing was found at this location. Maybe try one of the links below or a search?


The search still does not work