With this post, I’m starting a series of complementary articles dedicated to developing plugins for WordPress. The goal of our plugin will be to implement AJAX-based post search with autocomplete. To achieve this functionality, we’ll need to cover several topics, including:
- Plugin file creation
- Shortcode development
- Connecting styles and scripts
- Working with AJAX in WordPress
- Using jQuery Autocomplete
- Displaying post lists on the page and adding pagination
As you can see, there’s a lot of work ahead. For those just starting out with WordPress development, this should be especially useful.
Creating a Plugin
A plugin, like a theme, is a set of PHP, JS, and CSS files organized into folders and responsible for specific functionality. A theme, as you know, handles the visual appearance of the site (frontend). Actually, you can embed additional functionality into a theme — for example, a plugin — to expand its capabilities. But a plugin can’t become a theme or live independently. That’s why there are hundreds of different themes — for real estate, flights, news, and much more.
Both a theme and a plugin must have a “starter” file. In a theme, this is the `style.css` file with specific comments at the top. In a plugin, it’s any PHP file with special header comments.
As for the plugin file — I usually name it the same as the plugin’s folder for convenience. All WordPress plugins are located in the `/wp-content/plugins/` directory. Let’s name our plugin `wp-post-autocomplete`, and create a folder with this name. Inside it, we’ll also create a file named `wp-post-autocomplete.php`.
Open this file and add the following comment at the top:
/* Plugin Name: WP Post Autocomplete Description: Ajax article search with autocomplete Version: 1.0.0 */
Where:
Plugin Name — the name of the plugin
Description — a short description
Version — the current version number
In reality, there are more available parameters, but we’re using only the most essential ones here.
That’s it for now — lesson one is complete. Hopefully, we’ll “meet again” next week.
Full list of lessons in this series
- Lesson 1: How to Write a WordPress Plugin Yourself
- Lesson 2: Creating a Shortcode for the WP Post Autocomplete Plugin
- Lesson 3: Connecting Styles and JS Scripts for the Autocomplete Plugin
- Lesson 4: Working with AJAX in the Autocomplete Plugin
- Lesson 5: Integrating jQuery Autocomplete with the Plugin
- Lesson 6: Displaying Post Lists on a Page with Pagination
