I have tested on my localhost. It’s working fine 🙂
You can check it. Screenshot: http://nimb.ws/Vl1L0F
Default, WP has available support Autocomplete jQuery in Core. You can check it here. (find keyword ‘jQuery UI Autocomplete’).
You can try to follow my code and then test again 🙂
- Add code to
functions.php
.
add_action( 'wp_enqueue_scripts', 'add_scripts' ); function add_scripts() { wp_enqueue_style( 'jquery-ui- styles','http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css'); wp_enqueue_style( 'demo-styles','https://jqueryui.com/resources/demos/style.css'); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-autocomplete' ); wp_enqueue_script( 'custom', get_template_directory_uri() . '/assets/js/custom.js' ); }
- You create
custom.js
(you must check careful url contain file custom.js in your theme) to write js code.
jQuery(document).ready(function($) { var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; $( "#tags" ).autocomplete({ source: availableTags }); });
Done!.