Tutorial – CUSTOM USER LOGIN/SIGNIN USING AJAX IN WORDPRESS

146

Let’s get started.

HTML Code

This is just a normal HTML code and form for user to input username and password.

JS Code

Location and filename: THEME_DIRECTORY/js/theme-ajax.js
This code sends and display returned data in PHP code below

PHP Code

You can paste this code into your current theme’s functions.php file or create another file if you prefer.

Workaround

By default wp_ajax didn’t work in front-end or submitting data to admin-ajax.php file in front-end directly, luckily WordPress has wp_localize_script() function we can use, this function localizes a registered script with data for a JavaScript variable.

Paste the below code into your functions.php file, to avoid any conflict I suggest add it in init action

 

Leave A Reply

Your email address will not be published.