Home » Projects » Software Projects » Programming WordPress – The Basics

Programming WordPress – The Basics

programming WordPress with NetBeans

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.
  • JavaScript, another programming language, but rather than running on your server, it runs locally in web your browser.

Together with style sheets (CSS) which are used to customize appearance, PHP, HTML and JavaScript are the foundation of most web sites, including WordPress.

Programming WordPress requires learning a bit of each of these languages. If you have done some (even introductory) programming before, learning these is not hard. PHP and HTML are what you need the most; they are also the easiest. There are great resources online for PHP, HTML and JavaScript to teach you the basics and provide examples. The best place to start is W3Schools which covers them all. Another is Codecademy which actually provides structured online courses.

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.

Programming WordPress is done through text files that contain PHP, CSS, JavaScript, HTML or other stuff. You can write this code in a simple text editor like Windows Notepad, or the more advanced Notepad++ which adds features. For more serious work, you can use an Integrated Development Environment (IDE) like the free NetBeans, shown above. You can use NetBeans as a complete environment for programming WordPress: writing the code, uploading to your server and testing.

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.