Skip to content

PHP for WordPress Development: The Free Course

This free course on PHP for WordPress introduces the core topics you need to understand to practice the PHP side of WordPress development.

More than any other technical language, PHP is the language of WordPress.

Why learn PHP for WordPress? Well, more than any other technical language, PHP is the language of WordPress. WordPress is a PHP-based software package. PHP is WordPress’s skeleton and muscles—without it, there’s simply no such thing as WordPress.

How PHP and WordPress Fit Together

Like any language, PHP has a core “grammar”: how the language is set up. This is PHP itself, independent of the specific software package being written in it.

Then, the language also has specific “vocabulary”: software written in it. In this case, the most important grammar is WordPress’s enormous PHP codebase and function library.

So if you want to do WordPress theme development, WordPress plugin development, or code-savvy WordPress development more generally, you need to understand two core topics:

  1. PHP itself. This is the core “grammar” that WordPress developers need to understand to read and write PHP code.
  2. WordPress’s PHP code base. This is the WordPress-specific PHP “vocabulary” that lets WordPress developers do specific things, like fiddle with image sizes or register a new plugin.

Most of WPShout’s content discusses the second item above. This free course on PHP for WordPress covers the first items: PHP’s core grammar, as it applies to WordPress development.

As detailed as this material is, it’s just a preview of our upcoming PHP for WordPress Development premium course. That course will hugely streamline your learning, give you tons of WordPress-specific code examples to work with, and cover topics not in this free PHP course. Sign up here for updates on PHP for WordPress Development:

Okay, let’s get started on learning PHP for WordPress development!

1. PHP for WordPress: Core Concepts

PHP for Beginners: Starting on Backend WordPress Development

PHP and PHP Variables In a Nutshell

PHP is a very popular server-side programming language that is the core language of WordPress.

Perhaps the most basic PHP concept is variables, which look like:

$favoritecolor = "orange"; // Variable $favoritecolor now has value "orange"
$number = 20; // Variable $number now has value 20

2. PHP for WordPress: PHP String Concatenation

Learning PHP: Concatenate Strings and Variables Efficiently

PHP String Concatenation In a Nutshell

Concatenating (joining) strings in PHP looks like this:

$mystring = "Hello," . " " . "world!"; // Variable $mystring now has value "Hello, World!"

3. PHP for WordPress: Introduction to PHP’s echo

Learning PHP for WordPress Development: Understanding PHP’s echo

PHP’s echo In a Nutshell

In PHP, echo prints text to the HTML page:

echo "Hello, World!"; // outputs "Hello, World!"

4. PHP for WordPress: Introduction to PHP Functions

Learning PHP for WordPress Development: Introduction to PHP Functions

PHP Functions In a Nutshell

A PHP function looks like this:

function wpshout_print_greeting() {
	echo "Hello, World!";
};

wpshout_print_greeting(); // outputs "Hello, World!"

5. PHP for WordPress: Introduction to PHP’s return

Learning PHP for WordPress Development: Understanding PHP’s return

PHP’s return In a Nutshell

In PHP, return hands back a value when called:

function wpshout_get_greeting() {
	return "Hello, World!";
};

echo wpshout_get_greeting(); // outputs "Hello, World!"

6. PHP for WordPress: How to Include PHP in HTML

Learning PHP for WordPress Development: How to Include PHP in HTML

Including HTML in PHP In a Nutshell

Including PHP in HTML looks like this:

<h1><php echo "Hello, World!"; ?></h1>

7. PHP for WordPress: Introduction to PHP Logic Operators

Understanding PHP Operators of Logic, or || and && and ! a lot more

PHP Logic Operators In a Nutshell

PHP’s logic operators are && (AND), || (OR), and ! (NOT).

8. PHP for WordPress: Introduction to PHP Control Flow

Learning PHP for WordPress Development: Control Flow Basics

PHP Control Flow In a Nutshell

In PHP, control flow dictates when and whether code will run:

if ( $myvariable !== 100 ) :
	echo "Not 100"; // This code will only run if $myvariable is not equal to 100
endif;

if ( 1 === 2 ) :
	echo "Impossible..."; // This code will never run
endif;

9. PHP for WordPress: PHP Data Types

A Complete Guide to PHP Data Types: Numbers, Booleans, Strings, & More

PHP Data Types In a Nutshell

PHP has a variety of data types. Some main ones include:

$mystring = "100"; // $mystring is a string with value "100"
$myinteger = 100; // $myinteger is an integer with value 100
$myarray = [ 100 ]; // $myarray is an array with one array element, whose value is 100
$myboolean = false; // $myboolean is a boolean with value false

10. PHP for WordPress: PHP Arrays

A Thorough Introduction to PHP Arrays

PHP Arrays In a Nutshell

Arrays are a way of writing lists. In PHP, arrays look as follows:

$myarray = array( 1, "plums", false ); // simple array
$myassoc = array(
	"count" => 1,
	"food" => "plums",
	"purchased" => false
); // associative array

11. PHP for WordPress: PHP Math Functions

PHP Math Functions: Understanding the Basics

PHP Math Functions In a Nutshell

Most standard math functions work simply in PHP. Others have special functions, like the pow() function for exponentiation.

$myresult = 10 + ( 10 * 2 / 4 ) - 5 // $myresult is 10

12. PHP for WordPress: Understanding PHP Modulo

Understand PHP Modulo: Tricks with Division Remainders

PHP Modulo In a Nutshell

Modulo is a math function that calculates remainders. In PHP it uses the % symbol.

$myresult = 4 % 3 // $myresult is 1
$myresult = 8 % 3 // $myresult is 2
$myresult = 9 % 3 // $myresult is 0

13. PHP for WordPress: while() Loops

Learning PHP for WordPress Development: while() Loops

PHP while() Loops In a Nutshell

while() loops run multiple times in a row as long as a condition is true.

$i = 0;
while( $i < 10 ) :
	echo $i;
	$i++;
endwhile; // Will print out "0123456789"

14. PHP for WordPress: foreach() Loops

PHP Foreach: All You Need to Know

PHP foreach() Loops In a Nutshell

foreach() loops run along each element of a PHP array (or, rarely, another data type).

$fruits = [ 'peach', 'orange', 'pear' ];
foreach( $fruits as $fruit ) :
	echo $fruit . ' ';
endforeach; // Will print out "peach orange pear "

15. PHP for WordPress: Writing Strong PHP Conditionals

Three Tips for Writing Airtight PHP Conditions

PHP foreach() Loops In a Nutshell

foreach() loops run along each element of a PHP array (or, rarely, another data type).

$fruits = [ 'peach', 'orange', 'pear' ];
foreach( $fruits as $fruit ) :
	echo $fruit . ' ';
endwhile; // Will print out "peach orange pear "

16. PHP for WordPress: PHP Variable Scope

Understanding PHP Globals and Variable Scope in WordPress

PHP Globals and Variable Scope In a Nutshell

PHP variable scope describes when a particular variable is defined. PHP global variables—variables defined outside functions—are defined everywhere. PHP global variabes are generally not good coding practice, although WordPress makes heavy use of them.

$myglobal = "I'm defined globally.";
function first_function() {
	$mylocal = "I'm defined inside a function.";
}

function second_function() {
	echo $mylocal; // This will error: $local isn't defined here
}

function third_function() {
	echo $myglobal; // This will error
}

function fourth_function() {
	global $myglobal;
	echo $myglobal; // This will work
}

PHP for WordPress

I hope you’ve gotten a ton out of this free course on PHP for WordPress development. If you understand the topics above, you’re well on your way to grasping the core PHP topics you’ll need as a WordPress developer.

If you’d like to learn PHP for WordPress in the best and most complete treatment we can give you, sign up for updates on our full PHP for WordPress Development premium course, coming soon:

Thanks for reading!

Fred Meyer
Share:

4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Owen Mortensen
August 9, 2023 9:37 am

I was reading the WordPress developer documents (I haven’t written my first WordPress code yet!) and I noticed that they preferred the use of curly braces for things like if/else and while instead of the “if : endif” syntax. Is that correct? Or are they both equally acceptable?

Ajay
June 6, 2020 12:50 pm

This saves a lot of time of new developers

David Hayes
June 9, 2020 9:42 pm
Reply to  Ajay

Here’s hoping 🙂

Shafiq Lutaaya
April 26, 2020 2:07 am

This is very helpful for us WordPress developers

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!