• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Define a WordPress installation development mode

Discover in this tutorial how to define a development mode (core, theme, plugin…) in a WordPress installation using code.

In WordPress 5.5, the option to define a development environment with the WP_ENVIRONMENT_TYPE constant was added. In a previous tutorial you saw to use it to set the environment as production, development, staging or local.

With the arrival of WordPress 6.3 this option is complemented by a new constant called WP_DEVELOPMENT_MODE which allows you to indicate what type of development you are working in.

The values that can be assigned are:

  • An empty string (default): if you are not going to use it for development.
  • core: if you are using it for development related to WordPress core.
  • plugin: if you’re using it for plugin development.
  • theme: if you use it for theme development.
  • all: if you use it for development of everything mentioned above.

For now there aren’t many things that WordPress will run differently, but if you use core or theme mode it won’t cache the theme.json file, which can be very handy. Over time, more functionality will be added.

The nice thing about this is that it also opens the door to use different configurations depending on the environment.

Let’s see how you can define it:

Snippet to define a development mode in WordPress

Add the following snippet somewhere before the line containing “/* That’s all, stop editing! Happy publishing.*/” in wp-config.php file:

To see this and another 965 code snippets of this website, login or subscribe here.

Done!

In this case, you are indicating that the development mode is 'plugin', but you could use any of the ones mentioned at the beginning.

Once defined you can use the function wp_is_development_mode(), where you pass the parameter $mode (core, plugin, theme or all), to get different behaviors depending on the working environment.

Conclusions

Now you know how to define the development mode of your WordPress installation (core, theme, plugins…).

This opens the door to create functions that only run when you are in a particular development mode.

If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.

Benefits of being a subscriber. 🙂

PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?