How to prevent XSS attack in wordpress theme?

XSS generally would only occur through AJAX or form handling. Verify a referrer header is actually from your FQDN and/or require a captcha, providing pseudorandom input validation.