• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / WordPress .editorconfig

WordPress .editorconfig

Last updated on February 20, 2019 by Sal Ferrarello

The editorconfig project provides a powerful tool for standardizing the general coding standards used in a project, specifically in regards to:

  • indent_style (spaces vs tabs)
  • indent_size
  • end_of_line (lf vs cr vs crlf)
  • charset (e.g. latin1, utf-8)
  • trim_trailing_whitespace
  • insert_final_newline

The functionality of reading a project’s .editorconfig file is built into some editors and available in many others via a plugin. If your browser doesn’t already support an .editorconfig file, I suggest you install a plugin.

WordPress .editorconfig

The WordPress project uses the following .editorconfig as found at https://github.com/WordPress/wordpress-develop/blob/master/.editorconfig

# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

You can download this to your project directly from the command line with

curl -O https://raw.githubusercontent.com/WordPress/wordpress-develop/master/.editorconfig

Modified WordPress .editorconfig

I’ve made some modifications to the official WordPress .editorconfig file. Specifically,

  • Display a tab taking up 4 spaces in my editor (e.g. in a PHP file).
  • Use 2 spaces (instead of tabs) when working with JavaScript (and JSON) files.

You can download this modified WordPress .editorconfig file to your project directly from the command line with

curl -O https://gist.githubusercontent.com/salcode/285303f7983ad729b74d13d752214f4c/raw/.editorconfig

Here is a copy of my WordPress .editorconfig file.

# EditorConfig helps keep your project formatting consistent.
# See https://EditorConfig.org
#
# This is a modified version of the WordPress coding standards.
#
# Author: Sal Ferrarello (@salcode)
# https://salferrarello.com/wordpress-editorconfig/
#
# You can download this file directly
# to your project from the command-line with
# curl -O https://gist.githubusercontent.com/salcode/285303f7983ad729b74d13d752214f4c/raw/.editorconfig
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
[*.{js,json}]
indent_style = space
indent_size = 2
[*.yml]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[{*.txt,wp-config-sample.php}]
end_of_line = crlf
view raw .editorconfig hosted with ❤ by GitHub
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming Tagged With: code standards, editorconfig, WordPress

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in