PHP is an open-source, server-side scripting and programming language that’s primarily used for web development. The bulk of the core WordPress software is written in PHP, which makes PHP a very important language for the WordPress community. Some like to state that PHP as a programming language is dead but that’s not true.
There are different versions of PHP that you can install on your server, with the newer PHP 7.3 and 7.4 offering significant performance improvements. Those performance improvements, plus improved security, are why Kinsta always offers the most recent versions of PHP.
In this post, we’ll explain more about what “server-side” means and how PHP functions. Then, we’ll move into some of the ways that PHP specifically applies to WordPress and WordPress sites.
How Does PHP Work?
In the brief definition above, you learned that PHP is a server-side language. But what does “server-side” actually mean? Server-side means that all of the processing happens on your web server before anything gets delivered to your visitor’s browser.
Here’s an example. Say someone visits your WordPress site. Before sending any files to that visitor, your server will first run the PHP code contained in the WordPress core and any themes/plugins you have installed on your site.
Then, once your server has processed the code, it delivers the output of all that PHP (which is the HTML code that a visitor’s browser actually receives).
The end result is that, unlike HTML, your website’s visitors will never see the PHP code that powers your WordPress site. They’ll just see the already-processed code that your server delivers to their browser.
PHP 5 vs PHP 7
According to W3Techs, PHP is used by over 78% of all websites that use a server-side programming language, with ASP.NET coming in second place with a little over 10% market share.
Like other programming languages, there are different versions of PHP that you can use. PHP 5, 7.0, and 7.1 are older versions of PHP that have reached their end of life. This means they will no longer receive active support, and have ceased receiving security support.
PHP 7.4, the newest version, offers significant performance and security improvements. Currently, Kinsta supports:
You can even change PHP versions with a single click.
How Is PHP Used in WordPress?
If you go and download the latest copy of WordPress from WordPress.org, you can open the ZIP file to see that most of the included core WordPress files are PHP:
And any plugins that you install are – you guessed it – also going to be primarily PHP:
Beyond using PHP for its core files, WordPress also includes a huge number of functions, hooks, classes, and methods that you, or developers, can use to extend WordPress’ functionality in tons of helpful ways.
For example, one of the most well-known functions is
the_content();. While this small snippet looks innocent enough, it’s actually what your theme uses to display the entire content of each one of your blog posts.
Yes – that one tiny snippet can turn into a 10,000-word blog post after your web server finishes processing the PHP code. These functions, hooks, classes, and methods a big part of what makes WordPress flexible.
An Example of How PHP Works in a WordPress Theme
Let’s take things a bit further with a quick example connecting the server-side nature of PHP to your WordPress site.
If you go back to that picture of the Twenty Seventeen theme:
You’ll see that there are separate PHP files for things like “sidebar.php”, “header.php”, “comments.php”, etc.
If you already use WordPress, those terms should sound pretty familiar. And yes, it really is that simple – each of those files connects to the similarly-named area on the front end of your site.
- sidebar.php dictates how your sidebar area looks and functions
- header.php dictates how your header looks and functions
- comments.php dictates how your comments section looks and functions
Whenever someone visits your site, your web server takes all those separate PHP files for different areas in your theme, puts them together as specified by your theme, and delivers the completed HTML output to your visitor’s browser.
Do Regular Users Need to Know PHP to Use WordPress?
No! Not even close. The beautiful thing about WordPress is that all of the PHP is already written for you in the form of the core WordPress software, WordPress themes, and WordPress plugins.
While advanced WordPress users can use PHP to make more complicated customizations, casual WordPress users never need to concern themselves with PHP if they don’t want to.
What that being said, there are definitely benefits to learning the basics of PHP. Even just learning the most popular WordPress PHP functions will help you quickly make some easy, but significant, tweaks to your WordPress site. Make sure to check out our guide on how to use the phpinfo() function.
And if you want to develop your own WordPress themes and plugins, learning PHP is essential.