6JavaScript

In the first edition of this book, we wrote that JavaScript is “principally a language used to code plain‐text script executed on the client side, that is, the browser.” Since then, JavaScript has exploded into one of the world's most popular programming languages, and that statement is no longer completely accurate.

JavaScript can be used to power a web server using Node, and the web is now full of rich and powerful tooling that is pushing the boundaries of what is possible in‐browser. Even the bulk of the latest and greatest block‐based content editor is coded using nearly nothing but JavaScript.

This chapter covers best practices for getting your JavaScript files registered and enqueued inside WordPress. It will educate you on what JavaScript comes bundled with WordPress, including some oldies but goodies. It will help prepare you for the next chapter, which will put everything you've learned across multiple chapters to work using Gutenberg, the block‐based editing experience included in the latest versions of WordPress.

When it comes to JavaScript in WordPress, remember this:

  • Always register. Conditionally enqueue.

REGISTERING SCRIPTS

WordPress expects all JavaScript files ...

Get Professional WordPress Plugin Development, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.