Software Engineering in WordPress, PHP, and Backend Development

Category: Articles (Page 147 of 258)

Personal opinions and how-to’s that I’ve written both here and as contributions to other blogs.

Custom CSS in WordPress (Does It Conflict with Child Theming?)

From a developer’s standpoint, I have mixed feelings about having a built-in editor for editing custom CSS in WordPress. On one hand…

  • It’s a really easy way to make quick changes to the theme you have installed so you get the changes you want.
  • Then again, it also completely bypasses and defeats the entire child theme process.

As I’ve tried to think this through, I realize each serves a different purpose I’ll try to explain in a moment, but sometimes I can’t help but wonder if it makes things for difficult for users or more difficult for other developers than necessary.

Sounds weird, I know. But hear me out.

Continue reading

Maybe I’m Over Commenting Code (Are You?)

A couple of weeks ago, I was talking with a friend and a fellow developer about code, clarity, and generally over commenting code (how meta, I know).

The following statement was made about some of the code I write – and before I share it, I take no offense to this whatsoever. I dig these kind of discussions between peers.

Truth be told, I kind of agree with it.

I’m definitely less comment-y than you

When it comes to commenting code, I’m pretty verbose. This means I try to DocBlock everything from the server-side code to the the JavaScript and even add code blocks to my Sass (or even vanilla CSS) code.

Furthermore, I’ll comment on blocks of code that are used throughout my functions even though they may be only, say, 15 – 20 lines long.

This used to be something I constantly debated about myself, but I’ve stopped with it and accepted this is how I write code.

Continue reading

Ajax in WordPress: A Strategy For Error Codes

If you're reading this post in an RSS reader, don't forget to click on the "gist" link to see the code for the post.

In the previous post, I talked through the basics of setting of Ajax in WordPress on both the server-side and the client-side and how we can echo statements back to the client-side and why this is useful.

Ajax in WordPress: Error Codes

What I didn’t cover, though, was why this is important and how we can take advantage of it for gracefully handling any errors that occur throughout our code.

Whenever you’re dealing with a number of different variables such as user input, values of input fields, talking to the database, and network connections, there are a number of places in which the request and/or the response can fail.

And in those cases, we need to be able to make sure our project handles the situation well so we’re able to diagnose the problem and so our users aren’t left wondering what went wrong.

Continue reading

Ajax in WordPress: Custom Response Messages

I’ve talked about Ajax in WordPress in previous posts and it’s pretty well-documented in the Codex, so I don’t want to belabor the point on how to actually implement it.

Ajax in WordPress

Instead, the point of this post is to discuss how to implement custom response messages – or custom error messages – so you’re able to try/catch or gracefully handle the case when a request to the server fails.

That is, given the examples in the previous links we know how to implement Ajax in WordPress, but how do we handle the cases when something goes wrong? It’s not enough to simply write something out via console.log – after all, that’s meaningless to the user – but wouldn’t it be nice to actually display some type of message to let the user know what went wrong and how they can address it?

Continue reading

What Is the Assets Directory?

Last week, I wrote a short post asking What Is the Vendor Directory? which yielded a number of great responses, but it also resulted in a number of different questions, all of which were related, but none of which could be covered in that specific post.

For example, the article asked?

  • When do I know when to use a lib directory versus a vendor directory?
  • Should the vendor directory sit in the root of the project or should it exist in the root of, say, the JavaScript directory?
  • What about an assets directory?
  • Can lib and vendor co-exist?

And though some of these were answered in the comments and some of these answers can be found elsewhere, it did result in another question about the assets directory.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑