Behind the scenes of WordPress
WordPress is one of the most popular applications for managing websites. For the first time, the WordCamp took place in Frankfurt this year and offered the community the possibility to talk about topics and trends of the Content Management System. The numerous sessions about blogging, development, server and security contained everything that is interesting for the community. The talk “Goldmine WordPress – forgotten potential” by Mike Petzlaw was an exciting topic for the participants.
During his presentation the developer showed how extensive the core of WordPress is. More precisely, it’s about functions, libraries and snippets that are already included in the WordPress core. Oftentimes though they are not used, since some developers don’t even know they exist (or they don’t look up these functions in the core). For the frontend development JavaScript libraries are the main part. The most known library jQuery, for example, is just one of many.
To show the variety of the included JavaScript libraries, we will introduce two of them now.
Masonry: Pinterest’s favorite Layout
Masonry is a popular version for a layout, which is used by Pinterest for example. Elements take free space – no matter if they are next to or below each other. Technically, such a user interface cannot be developed only by using CSS but needs to be implemented with JavaScript. For this purpose, WordPress delivers the Masonry library in its core. WordPress only includes the script file itself because it is not needed by every theme or plugin. Hence, the developer has to implement it manually. Therefore, the following line needs to be written into the functions.php (themes) or the plugin file:
wp_enqueue_script( 'masonry' );
jQuery UI: Interactive Navigation and more
Another library from the jQuery family. WordPress does not only provide the base (namely jQuery) but also the whole jQuery-UI bundle. It contains, for example, animations, a date picker, accordion functions and position. Position makes it possible to map two elements to each other. This can be very helpful for dependent form fields, input fields based on other elements or interactive navigation bars. If you want to know more about JavaScript libraries that are included in the WordPress core, the best way is to download WordPress, open the /wp-includes/js/
folder and scroll through the scripts.
PHP-Constants for Backend Developers
For backend developers there are helpful functions and constants to influence the behavior of WordPress. For example, in order to stop loading all parts of WordPress you can use SHORTINIT to only load the WordPress-Class, the database, actions and the network. If you want to load more than that but not the themes and therefore not the HTML-Output, you can use the constant WP_USE_THEMES and set the value to true
:
define(‘WP_USE_THEMES’, true);
Another useful constant is CORE_UPGRADE_SKIP_NEW_BUNDLED
. This value gives you control over WordPress updates. If set to false, WordPress loads all its plugins such as Akismet and Hello Dolly and all its default themes, namely Twenty-Sixteen and other Twenty-* Themes. In most cases, these themes aren’t used because you use your own theme. In short, we can have a clean wp-content folder by using the constant true
.
Conclusion: Mike Pretzlaw was inspiring the audience by preparing a website http://wp-includes.org as an overview of all the functions, constants and libraries. Knowing all this, you can easily have a look behind the scenes of WordPress and check if the library you are about to use, is already included in the WordPress core.