So, you set up a free WordPress site way back when, and since then, you’ve been learning how to tweak it just the way you want. At first, that meant familiarizing yourself with the WordPress dashboard and the seemingly 8 million different pull down menus with their multiple options. Once you have all that under your belt, though, you’re ready to take the next step: doing the coding yourself.
What is PHP? How does it contribute to your WordPress site? How can you best learn to use it? We’ll go over the basics you need to know below.
What Is WordPress PHP?
WordPress is an open-source and free web-based content management system (CMS) used to build websites and manage their content. The original version was released in 2003 as a blogging platform. Since then, however, its use has grown to the point where it’s used for 30% of all websites. There is still a free version available at WordPress.com while paid accounts there offer custom domain names and additional features. Or, you can host one or more WordPress-powered sites on your own server or through a variety of third-party vendors.
WordPress software was developed using primarily MySQL and PHP. While MySQL works with databases, PHP is a server-side scripting language. It’s used for building web-based applications although it can be used for general programming, too. PHP’s power comes from its ability to be embedded directly into HTML, a web CMS like WordPress, and even web frameworks such as Laravel and Zoop.
When it comes to WordPress, PHP is used to create dynamic websites. As a point of comparison, a static webpage is one where content is fixed and presents itself the same way to every visitor. A dynamic website, however, uses server-side scripts via an application processor to determine how a webpage looks each time it is built for a new or repeat visitor.
For example, have you ever looked up a product on Amazon, and then soon after that, you saw an advertisement for it on Facebook, Instagram, or some other unrelated site? The webpages with those ads are dynamic because the product information on them was created just for you.
WordPress PHP Basics
There are three basic types of WordPress PHP files:
- Template: Uses a combination of PHP, HTML, and template tags to design the layout and look of different parts of your WordPress site.
- Core: Uses only PHP code and, among other functions, creates the top- or main-level directory and the admin files utilized by the WordPress dashboard.
When you’re starting out programming with WordPress PHP, you’ll be creating and editing the first two types of files above. Working with core files before you know exactly what you’re doing can break your WordPress installation. Once you’re an expert, though, the possibilities are almost limitless.
There are at least four tutorial modules at Treehouse you’ll want to check out:
- Beginning PHP: In this series of six tutorials totaling 15 hours, you’ll be introduced to HTML and CSS. Then, you’ll learn PHP fundamentals like conditionals and basic statements. From there, you’ll move on to PHP arrays and control structures, PHP functions, installing a Local PHP Dev Environment, and error handling. Finally, you’ll close out the course by building a basic PHP website.
- Intermediate PHP: This course contains seven tutorials which will also take 15 hours to complete. First, you’ll start with SQL basics and reporting before learning how to integrate PHP into databases. After that, you’ll move on to browser-persistent data and using SQL to modify databases. You’ll conclude with CRUD operations and file handling using PHP.
- WordPress Theme Development: This nearly four-hour course introduces theme template hierarchy, loops and other common functions, and how to set up menus and widgets.
Don’t limit yourself to just these tutorials. Treehouse has an extensive catalogue of over 220 courses – including even more on PHP topics – which have been utilized by 180,000 students.
Formerly known as Code School, Pluralsight has a variety of tutorials dealing with PHP and its use within WordPress:
- Try PHP: In this 36-minute tutorial, you’ll be introduced to PHP basics such as strings and data, arrays (simple, associative, and multidimensional), array functions, conditionals and operators, and loops.
- Close Encounters with PHP: In a little less than an hour, you’ll learn to use Composer for installation of the respect/validation library as well as the sanitization and validation of PHP forms.
- WordPress Custom Theme Development: Once you’re familiar with PHP basics, you’ll be ready for this almost 2.5-hour course about using PHP files to register widget areas, create different page and partial-page templates, and incorporate custom menus.
Like Treehouse, after you work through the basic tutorials above, you’ll be ready to tackle the advanced WordPress courses.
While many of the WordPress topics covered at WPMU are billed as tutorials, they are presented in a much less formal manner – lengthy blog posts – than the Treehouse and Pluralsight offerings above. That said, there is an extensive amount of information available about PHP, its use in WordPress, and related WordPress development topics. Here are some good articles to check out first:
- Learning PHP for WordPress: This lengthy, comprehensive guide begins with PHP basics before moving on to PHP’s use in WordPress. Then, you’ll learn how to take your programming skills to the next level even though, as this article admits, you’ll pick up some bad practices. That’s why enabling debugging is covered as well as using child themes and both queries and loops. There’s an excellent list of resources at the end you’ll want to look at closely.
- How to Write and Activate a Function in WordPress: When you’re finally ready to write your own WordPress plugin using PHP, this article will walk you through the process from beginning to end. This includes writing the function itself with a code editor, embedding the plugin into your theme, and subsequently testing it.
In addition, other WordPress tutorial topics include finding your WordPress login URL, building a marketing dashboard, and using template tags.
Last but not least, once you have a handle on your WordPress PHP basics, you’ll be ready to incorporate some of the quick and dirty shortcuts included in 17 WordPress Functions.php File Hacks:
- Hide your WordPress version number
- Display the total number of registered users
- Modify your dashboard footer
- Disable your RSS feed
- Add a simple text widget to your dashboard
Each of these hacks comes with plenty of code snippets and examples to show you exactly what you need to do to incorporate them into your own WordPress sites and dashboards.
Additional WordPress PHP Resources
Given WordPress’s ubiquity as a website builder and CMS, there’s a lot more to learn about how you can use PHP to create engaging, dynamic websites. In addition to the resources above, you should also check out these options:
- Codecademy: Its free, 4-hour beginner course has 11 units covering everything from loops to conditionals to object-oriented programming, and much more.
- Tizag: After you know your PHP basics, Tizag has a great collection of code examples to learn from even though the accompanying documentation is a bit light.
- Hacking with PHP: Once you’re ready to dive deeper into the PHP rabbit hole, this guide is your next step. It’s divided into 26 easily digestible yet comprehensive chapters with a review quiz at the end of each one. While it does focus on PHP 5.6, there is an option to access an expanded and updated guide for the newest PHP release.
One last thing to remember about all the resources above is the mindset they should instill in you: being a lifelong learner. After all, the only programming language which is static is one which isn’t used anymore. You’ll need to stay abreast of all the PHP news and developments to keep your websites operating at their full potential.
Interviewing for a job where you’ll be using MySQL? If so, you’ll definitely want to prepare by reading this list of questions (and answers!) on different MySQL topics.