WordPress

Articles, tips, and resources for WordPress-based development.

Removing HTML Comments in WordPress

Some time ago, I began removing the HTML comment label from beneath the standard WordPress comment form (no, not the Jetpack-enabled form – the one that ships with a default WordPress theme).

Most of you are familiar with the form as it generally looks something like this:

HTML in Comments

HTML in Comments

Generally speaking I find that that block that usually sits between the textarea and the submit input to introduce complexity and likely cause more confusion than anything else.

Adding Plugin Config Files to WordPress

Almost everyone who has worked with WordPress has dealt with wp-config.php. I know – there are a lot of managed hosts out there that take care of a lot of this for you – but even though a person may not have directly edited the file, they have definitely interacted with it.

For those who are unfamiliar:

This file is located in the root of your WordPress file directory and contains your website’s base configuration details, such as database connection information.

Anyway, for sometime now, I’ve been working on a relatively large plugin for a client and have recently taken to introducing a similar type of configuration files. So this raised that question, do what you think of plugin config files?

Tips for Saving and Retrieving Post Meta Data

One of the common things that I’ve seen – and personally done – is mismanaging $_POST data as it comes into the server-side from a form or some type of input element from the front-end. This may be in the case of sending data via Ajax or by doing a standard page refresh.

Chill Out, Veruca. We're getting there.

Chill Out, Veruca. We’re getting there.

Whatever the case, whenever you’re dealing with $_POST data in WordPress and you’re looking to save information into the database, there may be times where you’re interested in saving empty values, and there maybe times where you’re interested in savings values only if they are not empty.

If you’re going after the latter, there are a couple of safe guards you should introduce in your code to make sure that rows are only being written when there’s data to actually be written.

Custom Meta Box Tabs in WordPress

One of the things that has become relatively common within themes that offer a lot of options is the use of tabbed navigation. That is, options that are related are logically grouped into tabs and then the user can navigate through each tab in order to select the options.

Whether or not this is a good thing for themes is outside the scope of this particular post; however, another place in which tabs may also be used is within the context of custom meta boxes.

That is, a custom meta box sits below the post editor and it offers several options or additions to the post meta data each of which is group together in their own tab.

Though I personally find this a bit more effective than using tabs of pages for screen options, that discussion is outside the scope of this post.

Regardless, there are ways to improve the ways in which custom meta box tabs are created such that they are organized in a more maintainable way, and each tab has its own view, partial, or template so that it’s easier to work with over time.

WordPress Theme Updates Are New Themes

I know that there are different ways that people approach building WordPress themes and I’m not one to argue that there’s a single right way to do it. Sure, some ways are better than others, but that’s true of a lot of things.

Personally, I approach building themes, plugins, and so on as I would as if I was building some type of software. That has to do with my background. Similarly, someone who has a background in design and in front-end development will conceptualize what they are building in a different way.

Like I said, all of that’s fine (in fact, I think it’d be interested to see how different people view building themes, but I digress), but I do know that one common thing we always have to think about as it relates to updated our WordPress themes is the actual front-end design.

Specifically, does it make sense to completely change the design of a theme for a different version of the theme?

Single Page Tabbed Navigation in WordPress

In a couple of recent projects, I’ve been tasked with adding tabbed navigation to various WordPress templates. The thing is, these tabs work in such a way that all of the information is loaded on the page so when the user clicks on the tab, the contents of the page appear without having to do a page refresh.

Tabbed Navigation

 

In some cases, it may be best to load pages via Ajax, in some cases, it’s better to load things up all in the first page load. This particular post is about the best strategies for that (that’s a debate for another post).

JavaScript and WordPress Page Performance

Last week, I was having a conversation with a fellow WordPress developer about improving page performance as it relates to JavaScript. Specifically, we were talking about if it makes sense to load JavaScript sources at the bottom of the page.

If you’ve done any client-side development for a moderate length of time, odds are strong that you’re well-aware that it’s considered a best practice to include JavaScript sources before the closing body tag rather than in the head element.

This is because it allows the browser to render the page more quickly without waiting for larger files to download (and JavaScript files are normally heavier than HTML documents because of their file size and the processing they do on the DOM).

There’s a lot that could be said with respect to this in terms of general web development, but in terms of WordPress, opting to enqueue your scripts at the bottom of the page versus the top of the page may require a bit more consideration.

Why You Should Write Meaningful WordPress Meta Keys

If you’re someone who’s building solutions with WordPress regardless of if they are themes, plugins, or applications, then odds are you’ve had to deal with saving some type of information to the database.

Granted, anytime you create a post, a page, or anything that stores data, you’re entering information into the database.

But that’s not what I’m talking about.

Instead, I’m talking about times when you’re having to work with the Options API, the Theme Customizer API, or one of the meta APIs (like the Post Meta API). In this case, you’re working with the core application to save and retrieve information from the database.

When doing this – especially in development and possibly in staging – it’s likely that you’re having to write the code, run a test (automated or not), and then take a look at the way the record is stored in the database to make sure it saved as expected.

In my experience, there are a handful of things that can be done to make this process a little bit easier and make your code a little bit cleaner and one of these has to do with writing meaningful WordPress Meta Keys

Aim for a Single Way to Achieve a Single Task

When it comes to user interface design and user experience, I’m no expert (nor have I ever claimed to be). I’m barely an intermediate. if even that. I’m fortunate enough people to have peers who are willing to review certain projects in order to help tighten up certain aspects of my work.

I don’t think we should ever be afraid or ashamed to ask people who are more skilled than us in a certain area to help us out (or to pay them, even!). After all, we have nothing but to benefit from it.

This doesn’t mean that a couple of ideas, rules, and general practices haven’t come up over the years.

For example, one of the rules of thumb that I have whenever I am working on a user interface is to try to make sure the user only has one way of achieving something.

In other words, I don’t like it when there are multiple ways to do the same thing. I think that it confuses the user, it complicates the code, and it makes it more difficult to maintain over time. The code aspect of this is enough content for another post.

For now, it’s just about finding a single way to achieve one task.

Adding More Fields to the WordPress Media Uploader

Last week, I shared a short post on how to include your own instance of the WordPress Media Uploader in your theme or your plugin.

Though it walks you through everything that you need, on aspect of using the instance that I described is that it’s limited. This is fine for certain situations, but there are other times where you may want to grab more information from the user.

Case in point, the post received the following comment:

Now, how do you activate (turn on) the Insert Image via URL feature of the Media Uploader?

Which I thought was a good question especially given that most of us are used to seeing more options in the media uploader than what the previous post described.