WordPress: should I learn PHP?

Hi,

I’m not exactly new to coding but certainly new to serious web design, though I already completed HTML/CSS and JS courses on fCC. I have started picking up some work to help customize websites that are powered by Wordpress, and currently my prime objective is decluttering the website from the dozens of plugins it hosts to do simple things with pure code (this is to improve performance).

Right now, I want to make a contact form. I know how to do that with html, of course, but I’m not sure how to integrate with WordPress, and the few tutorials I found seem to be using PHP. Yet, these same tutorials are really quite cryptic or don’t explain anything besides giving you the code, which I don’t really find useful to understand what is going on, really.

So I guess, my question is: if I want to make something as simple as a custom contact form, is my only recourse PHP? And if so, can you recommend any good courses to learn it?

Cheers!

This depends on how you want it to fit into the WordPress way of doing things.

My answers below are assuming you don’t want to use an already existing Form plugin (something like Gutenberg Forms, Contact Form 7, or any of the plethora of other Form plugins that exist in the WP ecosystem). It’s worth considering why you’d want to re-invent the wheel here, but if you really want to do so here are some options off the top of my head (there may be others):

  • Create a page template in the theme (or child theme) for the form page—his is isn’t very flexible, in that the form will live only on that page—this may be fine if it does not need to be embedded in other pages throughout the site
  • Create a custom block that will allow one to drop in the form from the Gutenberg Block editor anywhere in a post/page.
  • Create a plugin that will allow one to drop in a short code to embed your form anywhere in a post/page

In any of the cases above, you’re going to need PHP and you’re going to need to familiarize yourself with the WP lifecycle and the various hooks and filters available to customize things. How much PHP you need to know and how much you need to familiarize yourself will depend on the route you choose. In any case WordPress has developer resources available, which is likely going to be your best starting place for digging in.

Ah great thank you so much for your help and all the ressources!

I am surprised you’d advice to use a plugin; granted there is a plethora of it, but isn’t it common knowledge that the already made plugins are often hurting the website’s performance - say, because they’re not tailored to the need, not called properly, etc. Isn’t it easier to maintain code when you know what everything is doing on a website? And finally isn’t our job as web developer to actually be coding?

Genuinely asking, would love to see if I’m completely mistaken about the way to go here :slight_smile:

Do you mean my advice to not reinvent the wheel and use an existing plugin that solves a problem? If so, let me preface that advice by saying, “depending on your goal or situation.”

For instance, if you’re a freelance developer and running a one-person agency using WordPress to generate (or enhance existing WP) sites for clients, you’re going to want to take advantage of the existing solutions to already solved problems, so you don’t have to write custom code from scratch every time.

In that particular scenario (agency-of-one), you are likely to build out your own custom theme (or become very familiar with a popular, well supported, highly-customizable existing one) so you know the ins-and-outs of it. You are also going to get to know the better plugins/blocks/templates out there for common things. Eventually, you’ll grow a list of your favorites (likely even creating a few of your own along the way for custom stuff where there isn’t already a usable solution).

If, on the other hand, your goal is to just create something for the sake of learning it or for a scenario where you think you can implement a better solution (or fill the needs of a market/problem where there is a gap) and you have the time to do so, then absolutely you should roll your own solution.

I wouldn’t call that common knowledge. I’d say that is a common misconception. There are WP sites using many plugins with good performance. Number of plugins isn’t always an indicator of bad performance. Quality of plugins used is certainly a factor, but number of plugins? Not as much as you’d think. Join some WP Performance groups if you’re interested in that, or if you don’t want to take my word for it, and ask around.

If you’re using a good plugin you can hook into it and tailor it to your needs. If you’re using a great plugin (open source plugin that is) you can contribute back things that make the plugin better for everyone. And if a plugin isn’t doing something properly, you should not be using that plugin.

Easier for who?

Easier for you, maybe. Easier for the person who has to maintain it after you? Answers to either probably depends on how much time goes by between building it and having to dig into it again to patch or enhance it. How well was it documented? How well was it built for maintainability/extensibility? How testable? Etc.

All the code for any themes/plugin you use is available to you—if you need to know what it’s doing you read the code. If you’re concerned about WP being a black box, it isn’t. The code is there to read—if you need to, but you often don’t because—it also has good supporting documentation of it’s inner workings.

Yes, certainly… but our job as developer is not just writing code all of the time. Reading existing code is a hugely important skill. Debugging existing code is a hugely important skill. Enhancing existing code is a hugely important skill. You will not always have the luxury of greenfield development (where you are starting from scratch and making all the decisions), you’ll eventually have to deal with brownfield development. You will be a more versatile developer if you are as comfortable on a greenfield project as you are on a brownfield one.

My advice was because you need to work with an already existing WordPress site. You don’t have to go with a n existing block or plugin if you really want to build something on your own. You can create your own page template/block/plugin, if you want to write it all from the ground up. You still have to play in the WordPress sandbox though (meaning, in it’s way of doing things). And if you do build it yourself, do let your client know what the options are for support and maintenance.

Are there other ways of doing it, sure. Look at a service like JotForm, which is not constrained to fit within the WordPress ecosystem. You could build your own similar (albeit scaled down) version of that using the whatever tech you wanted to make it so you can serve the form and it’s functionality externally and hydrate it using JavaScript. If you did that, you’d still need to provide either a custom page template, block, or plugin for it to be usable in the existing WordPress site.

To wrap up, you’re not completely mistaken. It was a good question. Like most things, the answer depends upon the details of the individual scenario.

1 Like