WordPress Command Line Interface (WP-CLI)

Developing for WordPress in Exeter and Plymouth

WP-CLI is a super-useful command line utility for WordPress developers. Instead of doing everything through the WordPress back-end, or using custom templates to render and debug your code, you can now interact with you site using simple commands from a console.

Developing this way may require an adjustment to your familiar workflow, but the learning curve is not steep, and the trade-off in terms of ease and power is definitely worth it! This post isn’t meant to be a tutorial, but to give you some idea of how easy WP-CLI can make your life, check out how easy installing WordPress becomes with using it:

wp core download
wp core config --dbname=wordpress --dbuser=root --dbpass=root
wp core install --url=http://localhost/dev/wordpress/ --title=WordPress --admin_user=username --admin_password=mypassword --admin_email=myemail@post.com

And that is all. You now have a working installation of WordPress!

Once installed you can run commands like: 

wp post list

to get a list of all posts from your site, or

wp plugin install bbpress –activate

to install and activate bbpress. And much, much more…

The project website is here for more info. I hope you enjoy using this fantastic tool.

For installation on Windows, this is what I did:

  • Install Compser from https://getcomposer.org/ using the Windows Installer
  • Open a command window and type just these two instructions:
    • composer global require wp-cli/wp-cli
    • composer global require psy/psysh
  • Now, navigate to a folder with a WordPress installation, and you can now use all that WP-CLI goodness to your heart’s content!

Creating a Custom Template for a Specific Post

Developing for WordPress in Exeter and Plymouth

Quick and Dirty WordPress Development Tip #1

There’s a lot of info out there about custom post types in WordPress. For example, there’s an excellent article here. But what if you only want to tweak the appearance or functionality of a single post? It seems a bit excessive to make a whole new custom post type for a one-off situation.

Enter WordPress’s super-cool file-naming system to the rescue!

Working on a child theme, as you absolutely should be, just create a file with the following format: single-post-{post-title}.php. For example, your file might be named single-post-spain.php. Then you can copy the contents of your parent theme’s single.php file, and make any changes you want. When the post with the named title is displayed, WordPress will automatically use the correct file.

This is similar to the method for displaying custom post types using single-{post-type}.php, but saves you having to make a new post type.

I hope this was helpful. Look out for future quick and dirty WordPress Development tips.


Modular Javascript

When you first start using JQuery as a developer, chances are you’ll write a whole load of sequential instructions which get the job done, but are hard to debug and become unwieldy as the project size increases beyond the very small.

This video series by LearnCode.academy really helped me as I was making the transition to more structured JavaScript. I hope you enjoy it as much as I did.