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 asldco-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 andenqueue_block_assets
for styles. All scripts are enqueued as ESM by adding thetype="module"
to included script tags. -
Miscellaneous Fixes and Cleanup
- Add a design credit to the WordPress dashboard.
- "Howdy" is removed from the admin menu bar.
- Lots of junk is removed from wp_head. Many optimizations come from the Soil plugin.
- WordPress will attempt to trigger a webpack devServer reload from the
save_post
hook. - Override the
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 thewp_login
hook, preventing the issue. This only runs on development environments when WP_DEBUG is set. -
Media Several media related features will be enabled:
- The JPEG Compression value can be set by defining a
JPEG_QUALITY
constant before invokingThemeInit()
. Numeric values will be clamped between 0-100 then passed to the WordPressjpeg_quality
filter.JPEG_QUALITY
defaults to82
. - A high-quality Lanczos scaling filter will be used for scaling images.
- All image uploads will be re-compressed if their filesize can be reduced by at least 75%.
- The JPEG Compression value can be set by defining a
-
Search A few improvements to native WordPress search
- Short-circuit search queries <2 characters long
- Redirect query searches to
/search/
- Workaround leading-dot search failures
-
SEO Framework Tweaks We apply several tweaks to the excellent The SEO Framework plugin:
- Hide the author's name
- Move the metabox to the bottom of admin pages
- Show the default image from the first post in archives
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.