Concepts for Custom Theme Development

If you’re new to WordPress development, there’s a couple techniques that will be incredibly useful when building themes for a specific company or purpose. Most WordPress themes available are built for general use, but when adapting it for a specific site it’s usually necessary to hardcode at least a few specific elements rather than make everything dynamic.

For example, it might make sense to hardcode the menu if it requires a lot of custom styling. It might make sense to query for specific pieces of known content. Certain pages may have a lot of art direction or targeted styles that would be incredibly difficult to build a custom UI for.

If you’ve already built a few custom themes, it’s likely know a many of these tips already- but hopefully there’s a few gems that will be useful for your toolkit. Continue reading

Version Control and Deploys with WP Engine

It’s taken me a bit of time to figure out the best way to version and deploy sites with WP Engine. I still don’t have a perfect solution, but it’s now much better than using an SFTP GUI to move the files from local to staging.

Version Control

In terms of version control, I like to have the active theme in its own repository. This is generally where the bulk of custom development work happens, and this makes it easy to view the commit history, open issues, and reference code. If custom plugins are needed for the site, I also like to have those in their own repositories for the same reason.

For everything else on the site (WordPress core, third-party plugins, and media) I think it’s important to have backup points (especially before plugin/core upgrade in case a rollback is required), but I don’t necessarily need to have that versioned with something like Git.

If you’re not like me and prefer to have the entire site versioned in one repository, then git deploys work great with WP Engine. You can even set the gitignore file to ignore specific third-party plugins, media, and core so it just tracks your custom plugins and themes- but those all still need to be in one single repository that is tracked from the root of the WordPress directory. Continue reading

Angular + WordPress JSON API

I’ve been wanting to get more familiar with the JSON API proposed for WordPress core and also with Angular (a javascript framework), so I decided to start building a little web app idea I’ve had for a while.

I’ve started small. My first experiment was just to see if I could connect to the JSON API and output a list of most recent posts. To do this, I built a basic theme with only the essential components: a stylesheet, a functions.php, an index.php, and the custom javascript.

You can find it on GitHub here. Continue reading

Administering WordPress from the Command Line through WP-CLI

Working with the command line can be intimidating if you’re used to a nice graphical user interface (GUI), but it’s worth getting familiar with. There’s a lot of mundane tasks in web development can be automated with good set of scripts and shortcuts.

It’s also often much faster and simpler to accomplish a task with the command line, and in this respect WordPress is no exception. WP-CLI makes it possible for you to get your WordPress related tasks done with the help of a set of commands.

You might have a natural question in your mind: if the WordPress admin interface is so gorgeous and user-friendly, why would someone like to use the command line interface? There are two key reasons:

  • People find keyboard faster than the mouse: Instead of using mouse, a power user always prefer to use keyboard shortcut to accomplish a task. In general, using keyboard shortcuts is 3 times faster than clicking a mouse.
  • Automation:To make several commands execute automatically, you just need to put them into a single text file. Automation saves a lot of your precious time.

So in this guide, I’m going to give you a taste of WP-CLI: a command line interface for administering WordPress sites. Continue reading

How to Disable Comments in WordPress

It’s surprisingly difficult to disable comments globally in WordPress.

Comments can be turned off for new posts in “Settings > Discussion” screen. However, all previously published posts would still retain their comment settings and need to be disabled individually under the “Discussion” metabox on the post edit screen (which can be very time consuming).

Disable Comments with One Click

The easiest way to turn off comments globally is actually with a plugin called “Disable Comments”, which is a free download from wordpress.org.

disable-comments

After enabling the plugin, you can choose to disable comments everywhere or only for specific post types. If you want the changes to be permanent, choose the “persistent mode” option before saving.

If you have chosen to make the changes permanent, the plugin can be deleted after you save the settings.

Deleting Comments

If a site was abandoned for a while or suddenly got hit by a lot of comment spam, you might want to delete all the pending comments or spam comments. For both of those scenarios, you can use a plugin called Delete Comments By Status.

Delete Comments By Status also allows you to delete “trash” comments and “approved” comments in bulk.

After enabling the plugin, go to “Settings > Delete Comments”.

Excerpt versus Content for Archives

Most theme developers have slowly moved away from using the_excerpt to display content on index, archive and search pages. I definitely have.

Let’s go over quickly how the_excerpt works:

  1. If an excerpt is explicitly defined, it will be displayed (including HTML).
  2. If an excerpt isn’t defined, the post content will be used, but stripped of HTML and truncated to 55 words by default. An indication that is has been truncated also displays “[…]”.

If a post consists entirely of a YouTube embed, a gallery, a single image, or a Tweet embed, “the_excerpt” will strip all that out- and thus nothing will be displayed. This makes for a very weird looking archive page if the_except is used.

The alternative is to use the_content. This allows the full content to show. But the content can also be truncated on archives by using more tag.

This is what I’ve been using in most of my new themes as it is the most flexible. Continue reading