PHPackages                             bernskioldmedia/wp-theme-base - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bernskioldmedia/wp-theme-base

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bernskioldmedia/wp-theme-base
=============================

A WordPress theme base that contains helpful base classes and functions that we can extend upon when developing WordPress themes.

3.0.0(4y ago)0471GPL-3.0+PHPPHP ^8.0

Since Oct 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/bernskioldmedia/wp-theme-base)[ Packagist](https://packagist.org/packages/bernskioldmedia/wp-theme-base)[ RSS](/packages/bernskioldmedia-wp-theme-base/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)DependenciesVersions (6)Used By (0)

WP Theme Base
=============

[](#wp-theme-base)

When creating themes we find ourselves having to reuse quite a lot of structural code. Therefore we've created this theme base class that houses all our "common" functionality.

Largely, this is a set of abstract classes that handles a bulk of common logic, giving you an option to enable/disable sets of features easily. It also interfaces with common third-party plugins that we use frequently.

Where possible it is modular, trying not to load more code than we really need.

How-tos
-------

[](#how-tos)

### Booting Hookable Classes

[](#booting-hookable-classes)

The theme base includes a contract, `Hookable` that requires a class to implement the `hooks()` method. This allows us to standardize classes that calls `add_action` and `add_filter`.

To boot up these classes within the theme, simply add the class names to the `boot` array in the main theme class.

```
/**
 * Boot the theme.
 */
protected static array $boot = [
    Asset::class
];
```

### Declare WooCommerce Support

[](#declare-woocommerce-support)

If the theme should support WooCommerce, enable WooCommerce support by, in the base theme class, setting:

```
/**
 * Support WooCommerce
 */
public static bool $supports_woocommece = true;
```

### Support Automatic Feed URLs

[](#support-automatic-feed-urls)

By default we disable automatic feed URLs. More sites than not don't need them in our builds. Enabling the support is easy. On the main theme class, just set:

```
/**
 * Include automatic feed links
 */
public static bool $supports_feeds = true;
```

### Support Post Thumbnails

[](#support-post-thumbnails)

By default we set post thumbnail support for posts only. You may include other post types, or disable support completely. On the main theme class, you can set the `$supports_thumbnails` property to an empty array to disable, or add other keys.

To disable completely:

```
/**
 * Disable post thumbnail support.
 */
public static array $supports_thumbnails = [];
```

To also add support for pages:

```
/**
 * Add thumbnail support for specified post types.
 */
public static array $supports_thumbnails = [
    'post',
    'page'
];
```

To add support for all custom post types:

```
/**
 * Allow thumbnail support for all post types.
 */
public static array $supports_thumbnails = ['*'];
```

### Change Custom Logo Support

[](#change-custom-logo-support)

By default we support a custom logo. You may want to change dimensions or disable completely. In the main theme class, set the `$custom_logo` to an empty array or false to disable completely or [change the options](https://developer.wordpress.org/themes/functionality/custom-logo/) to adjust.

```
/**
 * Add support for a custom logo.
 */
public static array $custom_logo = [
	'width'       => 400,
	'height'      => 50,
	'flex-height' => true,
	'flex-width'  => true,
];
```

### Add post formats support

[](#add-post-formats-support)

By default we don't ship with supports for [post formats](https://developer.wordpress.org/themes/functionality/post-formats/). Adding it is as simple as adding [the formats you want to support](https://developer.wordpress.org/themes/functionality/post-formats/) to the `$post_formats` array.

```
/**
 * Add support for post formats.
 *
 * @link https://developer.wordpress.org/themes/functionality/post-formats/
 *
 * @var array
 */
public static array $post_formats = [
    'aside',
    'status',
];
```

### Adding FacetWP Facets

[](#adding-facetwp-facets)

By registering the Facets in code we can both localize them, and make it easy to load between different environments. You both need to create a Facet class, and include it in the main theme class.

We suggest that you create a subfolder `Facets/` in your theme to store your facets. Creating your facets in the UI interface is simple. Grab the export code and port over to PHP easily.

Each facet will be an individual file. To create a category facet, this may look like:

File: `Facets/Category.php`

```
