A common baseline of repeated functions, filters and actions used across our WordPress themes.
Webpack dependency manifest asset loading
Uses the Dependency Manifest Plugin from ideasonpurpose/docker-build.
Scripts will be enqueued using the stylesheet "slug" combined with their entrypoint name.
For example, if the theme directory was ldco
, the following manifest entry would be enqueued as ldco-main
{
"main": {
"files": {
"main.js": "/wp-content/themes/ldco/dist/main-b4216f6b.js"
}
}
}
Editor assets are enqueued using the appropriate hooks; enqueue_block_editor_assets
for scripts and enqueue_block_assets
for styles. All scripts are enqueued as ESM by adding the type="module"
to included script tags.
Miscellaneous Fixes and Cleanup
save_post
hook.DISALLOW_FILE_EDIT
constant and block access to the Theme File Editor.ShowIncludes
A div showing all included theme files will be appended to the page when WP_DEBUG
is true. To disable it, initialize the class with an array containing: ['showIncludes' => false]
Template Audit
Adds a Template column to Pages admin and a summary table to the Appearance menu showing which templates have been assigned to pages.
Record Users' Last Login time User's last successful login are recorded and added to the WordPress Admin User table.
Reset Metabox Order & Visibility Adds buttons to the bottom of user profiles which will reset all metabox order and visibility from user_meta.
Enable and limit WP_POST_REVISIONS Revisions are set to 6, this overrides any constants set in wp-config.php.
Global Comments Disable
Comments and Trackbacks are completely disabled. To re-enable comments, initialize the ThemeInit class with an array containing: ['enableComments' => true]
Remove jQuery Migrate (optional)
Prevent jQuery Migrate from loading by removing it from the list of WordPress dependencies. To remove jquery-migrate, initialize the ThemeInit class with an array containing: ['jQueryMigrate' => false]
Admin Separators Admin Separators have been moved to their own library: wp-admin-separators
Remove Stale Login Cookies
Repeatedly spinning up local dev environments often bloats localhost cookies with stale wordpress_logged_in
entries. Once these accumulate, the local server will eventually fail with a bad request and the error message "Your browser sent a request that this server could not understand. Size of a request header field exceeds server limit." The cookie can be removed using the browser's dev tools, if the error is recognized -- but it often isn't. Instead, wp-theme-init removes stale login cookies from the wp_login
hook, preventing the issue. This only runs on development environments when WP_DEBUG is set.
Media Several media related features will be enabled:
JPEG_QUALITY
constant before invoking ThemeInit()
. Numeric values will be clamped between 0-100 then passed to the WordPress jpeg_quality
filter. JPEG_QUALITY
defaults to 82
.Search A few improvements to native WordPress search
/search/
SEO Framework Tweaks We apply several tweaks to the excellent The SEO Framework plugin:
Dependency manifest processing is designed to work with the WordPress Dependency Extraction Webpack Plugin. This omits a subset of script libraries included with WordPress, and outputs a PHP snippet for each entry point which includes a dependency list for enqueuing scripts.
The set of WordPress scripts which will be omitted is listed here and includes jquery
, lodash
, moment
, react
and react-dom
as well as all scripts from the @wordpress
namespace.
Run the PHPUnit test suite with: npm run test
This project is actively developed and used in production at Ideas On Purpose.