This is the third in a series of posts looking at the coding languages that form a WordPress site. It features a quick overview of how PHP works on you site.
What is PHP?
Created in 1994 by Rasmus Lerdorf, PHP is now a recursive acronym for PHP: Hypertext Preprocessor. A popular open-source general-purpose scripting language, PHP usually focuses on server-side scripting.
It is a very flexible tool that can be used for good (WordPress) 😉 or evil (Facebook) 🙁 . Other large users include Yahoo, Wikipedia, Tumblr, MailChimp, Flickr, Digg, and Baidu.
Sections of your WordPress pages and posts are stored in php frontend template files in your theme. These include:
- The Header
- The Footer
- The Sidebar
- The Loop – “Body Pages”
As seen in the image above, the WordPress Loop may contain index.php (homepage), archive.php, page.php, single.php, comment.php, or search.php files.
Much of your site’s functionality is coded in the functions.php file. Although more modern programming practices break it up into multiple modular components.
The backend of WordPress (admin area) is also built with PHP.
PHP: Hypertext Preprocessor
Like other scripting languages, PHP has variables, data types, operators, values, parameters, expressions, if…else…elseif statements, switch statements, loops, functions, arrays, scopes, and superglobals.
What does PHP do?
- PHP generates dynamic content
- PHP creates, opens, reads, writes, deletes, and closes files
- PHP stores form data
- PHP adds, deletes, and modifies data in your database
- PHP encrypts that data
- PHP sends and receives cookies
- PHP controls user-access
- and much more
WordPress is not a PHP framework but a CMS (content management system) that uses PHP code. PHP frameworks can also be used to build things other than CMSs and websites.
To quote Wikipedia frameworks are “an abstraction in which software providing generic functionality can be selectively changed by additional user-written code, thus providing application-specific software.
It provides a standard way to build and deploy applications and is a universal, reusable software environment that provides particular functionality as part of a larger software platform…
Software frameworks may include support programs, compilers, code libraries, toolsets, and application programming interfaces (APIs) that bring together all the different components to enable the development of a project or system.”
A PHP framework provides the core infrastructure for turning an incoming HTTP request into an HTTP response.
PHP frameworks include:
As you have seen, PHP is a much more complicated language than HTML and (to a lesser degree) CSS. It is the primary coding language that makes WordPress work. Like CSS, many books and websites cover extensive details of PHP. Since this is only an introductory article, below are some useful resources for you to explore.
- Introduction to PHP (How-Tos) – https://www.w3schools.com/php/php_intro.asp
- Official PHP Site – https://www.php.net/
- WordPress PHP Coding Standards – https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/
- PHP: The Right Way – https://phptherightway.com/
- Custom WordPress Page Templates – https://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/
- PHP Snippets, Functions, Tutorials & Tools – https://phpbuilder.com/
- Zend PHP Blog – https://www.zend.com/blog
- What’s Coming in PHP8? – https://stitcher.io/blog/new-in-php-8
- LAMP, the WordPress Software Stack – https://en.wikipedia.org/wiki/LAMP_(software_bundle)