How to get started with PHP for WordPress Development

If you are just getting into WordPress development then get ready to learn PHP. A WordPress user does not need to learn PHP to use, run, or manage a WordPress powered website. However, if a user wants to develop WordPress themes, plugins, or modify default behavior of WordPress by using actions and filters, then they would need to learn the basic syntax of PHP along with HTML and CSS. PHP is much more complete on its own right than people realize. Not only it has a built-in web server which is good for development and simple intranet needs, but it also comes with SQLite, which has a powerful query engine and is ideal for all your database needs, right up until you start getting those coveted millions of hits per hour on your site (at which point you can migrate to bigger databases).

If you are ‘just’ starting to learn PHP and it is your first language so far go with the suggestions of using online tools like PhpFiddle. It’s good for getting you learning the basics.

For simple pages, you use their online editor to write and test code. but for more complex projects, having some sort of server available is definitely required.

If you don’t want to bother with setting up a local server, there are tons of free web space providers out there, offering limited space, but also often PHP and MySQL. Might not be the best or fastest, but for learning purposes, they will suffice.

There are tons of ways to get access to server functionality. XAMPP is just one of those, that’s comparably easy to work and that is available for all Operating systems.

Sites like Code Academy will help you get started and reading resources. Once you get into the meat of it, you can start learning frameworks and design patterns. When you want to make your own scripts, install PHP locally and run your code via the command line/terminal. PHP has it’s own built-in web server that you can invoke at the command prompt.

Why learn PHP for WordPress Development?

 In WordPress PHP files usually have a .php extension. PHP can be used inside HTML documents. The PHP pre-processor only processes code inside the php opening tag <?php and the closing tag ?>.

WordPress has a few different types of PHP files:

Core files – usually contain only PHP code and are not files that you should edit since that may break your WordPress install.

Plugin files – contain primarily PHP code although may have some HTML, CSS, and JavaScript mixed in with them. You do not generally edit plugin files unless you are building a plugin yourself or making changes to someone else’s plugin.

Theme files – contain a combination of PHP and HTML and are the most common types of files you will find yourself editing.

Within all of the different types of PHP files, you will find what’s called a PHP block. When you write PHP you need to write it inside of PHP blocks otherwise it will display as plain text and not be processed as a programming language by the server.

A PHP block starts with a “<?php” and ends with a “?>”. Blocks can span many lines or sometimes appear inline along with other code.

Here is an example of a PHP block with a PHP comment inside of it.


// Example of a PHP Comment


When you are working inside of template files you will often see short PHP blocks that appear within HTML tags like the one below. This is an example of how you would display the title of a post inside of an h1 tag.

<h1><?php the_title(); ?></h1>

Many of the WordPress core files don’t actually ever close their PHP blocks because the server will close them automatically. However, in general, you should close your PHP blocks.

So with PHP, you can get into the code to really customize things and get a site to look or behave exactly how you want. You can save content to a database, read content from a database, write loops and conditional statements, pull in images, media and WordPress specific information and other PHP, CSS and JS files.

sarah ali

sarah ali

Sarah is a passionate writer and blogger. As an early adopter, she enjoys trying out new social media and Internet tools along with WordPress plugins and Web apps.
sarah ali

Leave a Reply

Your email address will not be published.