How I modernise WordPress theme code with PressGang

For agencies looking for a dependable, modern WordPress development pipeline, I show how PressGang streamlines delivery using a legacy theme migration as an example.

In this article, I’ll walk you through a recent WordPress site modernisation. The site broadly worked well, but its code was dated and it ran on an obsolete PHP version.

In an agency environment, you need to build and maintain many WordPress themes. Clear structure, less repeated code and shared conventions each remove a little friction from that pipeline.

Think of a well-equipped workshop where the tools are kept in different places on every job. You can still produce good work, but you spend time finding your bearings. A familiar layout lets you carry what you’ve learnt into the next job.

With PressGang, I’ve worked on those marginal gains to streamline the workflow and make WordPress a pleasure to develop with.

Beautiful code for developers.
A dependable workflow for project managers.

Give every responsibility a home

This migration started with a roughly 1,200-line functions.php. Theme setup, hooks and shared data had accumulated in one file. Finding a feature meant searching through everything else.

PressGang is opinionated about where code belongs. Each responsibility has a home:

config/             # Registration and site configuration
src/Controllers/    # Prepare data for templates
src/Models/         # Content-specific behaviour
src/Traits/         # Shared queries and getters
src/Snippets/       # Hooks and reusable behaviours
views/              # Twig templates

Names that tell you where to look

Composer’s PSR-4 autoloader maps namespaced classes to files. A controller belongs in src/Controllers/. Its namespace reflects that location. Composer loads the class when it is used, without another hand-written require_once.

Namespaces also keep your theme’s classes separate from those supplied by plugins and packages. Meaningful class names become practical without inventing a unique prefix for everything.

Fewer decisions. Faster development.

Those conventions give the team fewer routine decisions to make. Everyone knows where to start:

  • ✅ Page data lives in controllers.
  • ✅ Presentation lives in Twig templates.
  • ✅ Registration belongs in config: menus, post types, taxonomies, etc.
  • ✅ Hooks and reusable behaviours belong in focused snippets.

Each change has a smaller, clearer home. Files become easier to navigate, review and maintain.

For an agency, that familiarity carries into the next project. Developers spend less time finding their bearings. PressGang brings the recognisable structure that makes Laravel so popular in the PHP world into your WordPress development.

Configuration replaces boilerplate

PressGang puts menus, post types, taxonomies and other setup in predictable configuration files. Conventions determine where those files live and how they are loaded. You declare what the site needs. PressGang handles the registration. That removes repeated setup code and gives each setting a clear home, so you know where to look when it needs changing.

Before: buried in boilerplate

This post type registration looks fine on its own. Bury it among hundreds of lines in functions.php, and finding a setting becomes a search through unrelated code.

add_action( 'init', function () {
    register_post_type( 'publication', [
        'labels' => [
            'name'          => 'Publications',
            'singular_name' => 'Publication',
            'add_new_item'  => 'Add new Publication',
            'search_items'  => 'Search Publication',
            'all_items'     => 'All Publications',
            'edit_item'     => 'Edit Publication',
            'update_item'   => 'Update Publication',
            'new_item_name' => 'New Publication',
            'menu_name'     => 'Publications',
        ],
        'public'            => true,
        'show_in_nav_menus' => true,
        'supports'          => [ 'title', 'editor', 'revisions' ],
        'has_archive'       => 'publications',
        'rewrite'           => [ 'slug' => '/publications' ],
        'menu_icon'         => 'dashicons-media-default',
    ] );
} );

After: easy to find. Easy to change.

The same post type lives in config/custom-post-types.php. One predictable place to find its settings and change them.

<?php
return [
    'publication' => [
        'public'            => true,
        'show_in_nav_menus' => true,
        'supports'          => [ 'title', 'editor', 'revisions' ],
        'has_archive'       => 'publications',
        'rewrite'           => [ 'slug' => '/publications' ],
        'menu_icon'         => 'dashicons-media-default',
    ],
];

PressGang generates and pluralises the labels from publication. You declare the settings; PressGang handles registration. Less boilerplate to maintain, with one predictable place to make changes.

Give logic and layout their own space.

PressGang introduces controllers to prepare page data. Timber passes that data to Twig for presentation. You can change the query in PHP and work on the layout in Twig, with each concern in its own place.

Familiar WordPress routing. Less wiring.

WordPress would normally load archive-publication.php for this listing. You can keep that PHP template as an entry point to a PressGang controller. Or let PressGang’s dispatcher select the controller by name, with explicit mappings in config/controllers.php when you need them.

'archive-publication' => [
    'controller' => \MyTheme\Controllers\PublicationsController::class,
    'template'   => 'page/publications.twig',
],

Fewer PHP files whose only job is to pass data to a template. A small saving that adds up across a theme. You can also reuse a built-in controller when only the Twig template needs to change.

Prepare the publications

The controller adds to Timber’s shared context.

protected array $context_getters = [
    'publications' => 'get_posts',
    'heading',
];
protected function get_posts(): \Timber\PostQuery {
    // Build and return the publications query here.
}
protected function get_heading(): string {
    return 'Publications';
}

Through $context_getters, get_posts() supplies the publications collection, while get_heading() supplies the page heading. PressGang makes both available as variables in Twig.

This theme uses Quartermaster for fluent query building, which I’ll cover in a future article.

Keep the view readable

Twig uses the heading and publications prepared by the controller. The template stays focused on displaying them:

<h1>{{ heading|e }}</h1>
{% for publication in publications %}
    <h2>{{ publication.title|e }}</h2>
    <p>{{ publication.meta('excerpt')|e }}</p>
{% endfor %}
{% include 'partials/modules/pagination.twig' with {
    pagination: publications.pagination()
} %}

The route, query and layout each have a clear home. Change the filtering in PHP or redesign the listing in Twig. Each change is easier to locate and review.

Keep code modular with snippets.

WordPress plugins make code reusable and keep it separate from the theme. But they also introduce an installation and activation lifecycle. For small pieces of theme setup, developers often want that choice to live in code.

PressGang snippets provide that modularity through classes enabled in the theme’s configuration. Hooks, setup and recurring behaviours can stay small and focused without each needing a custom plugin.

<?php
return [
    'ThemeDisableEmojis'      => [],
    'ThemeRemoveGalleryStyle' => [],
];

With pressgang-snippets, your team can share those pieces across themes and projects. Composer manages the library, and developers control what each theme enables.

For agencies and developers that care about code.

Modernising a theme is a chance to make the next change easier. With PressGang, configuration, queries and templates each have a clear home, and useful code can be shared across projects.

For agencies, that means a familiar starting point for each build and less repeated setup. For developers, it means WordPress code that is easier to understand, maintain and enjoy working with.

Get started with PressGang

Want to bring PressGang into your agency workflow?

I’d be very happy to help your team get started, whether you’re migrating an existing theme or setting up a shared approach for future projects. Contact me for a free consultation.