Lesson 1. How to write a WordPress plugin yourself.

Lesson 1. How to write a WordPress plugin yourself.

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:

  1. Plugin file creation
  2. Shortcode development
  3. Connecting styles and scripts
  4. Working with AJAX in WordPress
  5. Using jQuery Autocomplete
  6. 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

Posts on similar topics

Are you having problems with your WordPress site? Do you need additional functionality? A custom plugin or a new page?
Then write to me via the feedback form, and I will try to help you.

Write a comment

Your email address will not be published. Required fields are marked *