If you are not afraid of a bit of code, there are some amazing things you can do programming WordPress.
When you use WordPress for your web site, there is no requirement to do any “programming”. It’s all there, out of the box, using themes and plugins that other people have developed. This web site is a great example of using WordPress without any programming. I did not have to write a single line of code for this web site. (Well, actually that’s not true. There is one single line of code I modified in my theme.)
Currently, I am building a second WordPress web site called Complexity Itself. It will go live later this year. Since I want some advanced features that are not available free “off the shelf”, I have taught myself a bit about programming WordPress.
There are three programming languages essential for programming WordPress. These are:
- PHP which is a scripting language that runs on your web server. You use PHP tell your WordPress server what to do.
- HTML which is hypertext markup language. You use HTML to tell your WordPress server how to display something.
Programming WordPress does not require making any modifications to the core WordPress code. You simply use it. WordPress provides hundreds of functions that do specific things, and all are well documented in their Codex. More important, WordPress provides many places (called “hooks”) where you can insert your own code to do special things while WordPress runs. For example, I have hooked into the WordPress function that saves a new page, and my custom code does some automated editing and insertions just before the page is saved. Similarly, by working with a “child” of your theme, you do not modify the theme itself.
Programming WordPress – Where to put your code
There are two places where you can put your own code to customize WordPress. The first, and easiest, is into the pages of your Theme. The Theme is what provides the visual structure and design of your WordPress web site. This is done through PHP templates (scripts) for each type of page in your site. You can edit your theme directly within WordPress dashboard. Most people make a copy of the theme, called a “child” and do the editing in the child. That way the original theme is preserved. For example, every time WordPress shows a page, it uses a pre-built template called “page.php”. If you create a page called “mypage” and want a different display template, you just create a new template called “page-mypage.php” and WordPress will use it. Customization made simple.
The second way to add code to WordPress is to use a plugin. A plugin is some code that hooks into WordPress according to your instructions. Plugins are basically PHP scripts that can perform functions. In the picture above, you can see some code that I have written for WordPress plugin. This code is just saved into a folder in WordPress called “plugins” and after that, you activate your plugin and it WordPress runs it.
In the next article, I will describe how to set up your own local development environment, including your personal WordPress server on your LAN. That’s all you will need to start programming WordPress.