Make header search box JS conditional on it existing

Prevents some JS errors from being thrown by making it conditional.