JavaScript and PHP Libraries Used by WordPress

Share this article

Key Takeaways

  • WordPress relies heavily on third-party JavaScript and PHP libraries, with jQuery being the most heavily used JavaScript library, and PHP libraries mainly consisting of single class files. Other JavaScript libraries used include jQuery Masonry, jQuery Hotkeys, jQuery Suggest, jQuery Form, jQuery Color, jQuery Migrate, jQuery Schedule, jQuery UI, Backbone, colorpicker, hoverIntent, SWFObject, and TinyMCE.
  • WordPress’s third-party libraries live alongside WordPress files in the wp-includes and wp-admin folders. PHP libraries are named with class-*.php or live inside their own folder, while JavaScript files reside under these folders in the js folder. CSS files are mainly jQuery or TinyMCE CSS files, found under the CSS folder in the include folders.
  • While these libraries enhance WordPress’s functionality and user experience, many are outdated, sparking discussions on architecture and potential improvements such as Bower and Composer integration with WordPress. Understanding these libraries can lead to smarter and faster work with WordPress, and potentially contribute to its core.

Almost all modern software (including platforms such as WordPress) rely on third party libraries. That’s because, as developers, we don’t need to reinvent the wheel.

If I had to develop software that uses HTTP abstraction, I might use a package like Symfony HttpKernel or similar. If my software needed more than that (unlikely by the way, but let’s imagine that for our example), I could extend that package, or in the worst case, create one from scratch. Creating something from scratch isn’t a bad thing. It can actually be a good thing, since it makes you a better developer. But commonly, in most modern projects, you’ll have to depend on third party libraries (or packages). In this article we’ll take a look at the various third party JavaScript and PHP libraries used by WordPress.

List of Used Libraries in WordPress

In WordPress, third party libraries live alongside WordPress files. To better understand how files are structured in WordPress, the WordPress Codebase page will give you some answers. The wp-includes folder holds some of the libraries that are included when the application is executed. Also, in wp-admin you’ll find a second include folder that does the same as the first. In both folders you will find PHP and JavaScript files.

The third party PHP libraries are named with class-*.php (single files) or live inside their own folder. Other PHP files named class-*.php can be WordPress files (not third party). PHP files live under the wp-include or wp-admin/include folders.

JavaScript files also reside under these folders, but they are grouped in the js folder.

The CSS files are mainly jQuery or TinyMCE CSS files, found under CSS folder in the include folders.

JavaScript Libraries

Let’s start with the JavaScript libraries. WordPress uses jQuery heavily. It uses:

As you might notice, some of these libraries don’t have a link. That’s because some are them are very old and the repos don’t exist anymore. Let’s check them out one-by-one.

jQuery is a famous library, one that doesn’t need an introduction.

jQuery Masonry is plugin that makes easier to create masonry layouts like this one:

jQuery Masonry plugin

Layouts like this are a bit hard to do from scratch, jQuery Masonry makes this easy.

jQuery Hotkeys deals with shortcuts on the browser. If you’re used to tools such as StackEdit.io, you may use ‘ctrl+s’ (command+s) to save a file on gDrive or other cloud providers. The (ctrl+s) shortcut by default in your browser can be used to save a web page, using this plugin you can override these default shortcuts.

jQuery Form deals with forms and AJAX calls. If you’re curious and want to learn more about this plugin, you can check out their docs.

jQuery Color is used by WordPress for color manipulation and animation.

jQuery("#go").click(function(){
    jQuery("#block").animate({
            backgroundColor: "#abcdef"
    }, 1500 );
});

The first line selects the element with id="go" and tells the browser that it should animate the background color of the element with id="block" in 1.5 seconds.

jQuery Migrate helps you when dealing with earlier jQuery codebases. This is very important for WordPress because it is a platform that should be backwards compatible.

As a matter of fact, backwards compatibility is one of the most well known features of WordPress. On the other hand, it’s one of the problems with WordPress. WordPress was released in 2003, the PHP version that was used for that release is ancient. Today, PHP is a modern language and has borrowed many useful features from other languages. But this is another topic, one for a future article.

WordPress also uses other JavaScript libraries, not just jQuery. Here are some other popular libraries it uses:

And the list goes on and on.

The most famous from this list is TinyMCE and Backbone. TineMCE is used to compose new Posts and Pages in the WordPress dashboard.

Backbone is a front-end framework, in fact it was one of the first. It is still being used today, but loosing a lot of market share from Angular and other front-end frameworks. And yes, I’m talking to you Meteor. But don’t worry, in the JavaScript universe, frameworks (libraries) are forgotten as fast as they become popular.

PHP Libraries

The list of PHP libraries is a bit different. We saw that JavaScript was mainly influenced by jQuery and some other popular libraries. With PHP, things are different, as most of the third party libraries are just one class (file). Here’s a short list of the current third party PHP libraries:

An Open Discussion

Many of the libraries are a bit outdated. This is when discussions on topics such as architecture tend to happen. I would personally like to see Bower and Composer integration with WordPress. I would like to ask the SitePoint community about these ideas, and have an open discussion on how things can be improved with WordPress. Please leave your comments and thoughts below.

Conclusion

In this article we’ve seen the various third party libraries that WordPress uses. Knowing what WordPress uses behind the scenes, you’ll have a much better understanding on how it works. The better your understanding, the faster and smarter you’ll be able to work with WordPress. Maybe you can even work towards contributing to WordPress core. After all, this is the world of Open Source, we learn from each other and share ideas (both code and pizza!).

Frequently Asked Questions about JavaScript and PHP Libraries Used by WordPress

What are the most commonly used JavaScript libraries in WordPress?

WordPress uses several JavaScript libraries to enhance its functionality and user experience. The most commonly used ones include jQuery, Backbone.js, and Underscore.js. jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversal, event handling, and animation for rapid web development. Backbone.js gives structure to web applications by providing models with key-value binding and custom events. Underscore.js is a utility-belt library that provides support for the usual functional suspects without extending any core JavaScript objects.

How do PHP libraries enhance WordPress functionality?

PHP libraries are a collection of classes and functions that are used to perform specific tasks in WordPress. They help in enhancing the functionality of WordPress by providing pre-written code to perform common tasks, thus saving developers time and effort. For instance, PHPMailer is a code library used to send emails safely and easily via PHP code from a web server. Similarly, SimplePie is a PHP library that can read RSS and Atom feeds.

How can I add JavaScript to my WordPress site?

There are several ways to add JavaScript to your WordPress site. One of the most common methods is by using the wp_enqueue_script function. This function includes the specified JavaScript file in the page. Another method is by adding the JavaScript code directly to your theme files. However, this method should be used with caution as it can lead to issues if not done correctly.

What are some of the best PHP libraries for WordPress development?

There are several PHP libraries that can aid in WordPress development. Some of the most popular ones include Guzzle, a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services; Carbon, a simple PHP API extension for DateTime; and Monolog, which helps to create logs.

Can I use third-party JavaScript libraries in my WordPress site?

Yes, you can use third-party JavaScript libraries in your WordPress site. However, it’s important to ensure that the library doesn’t conflict with any existing scripts on your site. Also, you should always use trusted sources when downloading third-party libraries to avoid security issues.

How can I update the PHP libraries in my WordPress site?

Updating PHP libraries in your WordPress site can be done by downloading the latest version of the library and replacing the old files with the new ones. However, it’s important to backup your site before making any changes to avoid losing any data.

What are some of the best WordPress plugins for managing media files?

There are several WordPress plugins that can help manage media files. Some of the most popular ones include WP Media Folder, which allows you to organize your media files in folders; and Smush, which helps to optimize and compress your images.

How can I add JavaScript to WordPress posts or pages?

Adding JavaScript to WordPress posts or pages can be done by using the Custom HTML block in the Gutenberg editor. Simply paste your JavaScript code into the block and it will be included in the page when it’s viewed.

What are the benefits of using JavaScript and PHP libraries in WordPress?

Using JavaScript and PHP libraries in WordPress can greatly enhance the functionality and user experience of your site. They can help to simplify complex tasks, improve performance, and provide additional features that would be difficult to implement from scratch.

Are there any risks associated with using JavaScript and PHP libraries in WordPress?

While JavaScript and PHP libraries can provide many benefits, they can also introduce risks if not used properly. For instance, using outdated or poorly maintained libraries can lead to security vulnerabilities. Also, using too many libraries can negatively impact the performance of your site. Therefore, it’s important to use libraries judiciously and keep them up to date.

Aleksander KokoAleksander Koko
View Author

Aleksander is young developer who loves to play with the newest web technologies. In his free time, he reads about PHP, Firefox OS or experiments with a new language. Currently, his main interests are PHP design patterns, laravel, dart and cloud.

backboneChrisBFrameworksID3javascriptjQuerylibrariesPHPphpmailerSimplePieSWFObjecttinymceWordPress
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week