Config placement using the WP-CLI anchor

Why does the wp config set WP-CLI command add a constant or variable where it does?

wp config set DB_ENGINE sqlite

This command will add the constant to the wp-config.php file right before the “That’s all, stop editing!” line, exactly where WordPress suggests people should stop adding “custom values”:

/* Add any custom values between this line and the "stop editing" line. */

define( 'DB_ENGINE', 'sqlite' );
/* That's all, stop editing! Happy publishing. */

“Behind the scenes”, the wp-cli/config-command leverages the WP Config Transformer to “programmatically edit a wp-config.php file”. By default, it treats that comment as its “placement anchor string”,

Control where the config is added

However, if you want to, you can control where the constant is added.

For example, you might think the DB_ENGINE constant would be better placed with the other database settings.

Using the anchor option, you can do exactly that:

wp config set DB_ENGINE sqlite --anchor="/** The name of the database for WordPress */"

This adds the constant right before the specified string:

// ** Database settings - You can get this info from your web host ** //
define( 'DB_ENGINE', 'sqlite' );
/** The name of the database for WordPress */
define( 'DB_NAME', 'your_db_name' );

With the separator option, you can also add some breathing room:

wp config set DB_ENGINE sqlite --anchor="/** The name of the database for WordPress */" --separator="\n\n"

Like so:

// ** Database settings - You can get this info from your web host ** //
define( 'DB_ENGINE', 'sqlite' );

/** The name of the database for WordPress */
define( 'DB_NAME', 'your_db_name' );

For even more flexibility, you can use the placement option to control whether new values are placed before or after the anchor.


While the WP Config Transformer can insert constants and variables (--type=variable) before or after a given string, it can’t insert arbitrary PHP comments or code. (Although, it would be useful in many cases.)

Its main purpose isn’t to be a “general text editor”. Most of its code focuses on normalization, validation, ensuring there are no duplicate constants, and so on.

All rights reserved © 2025