PHPackages                             developwithwp/metabox-control - 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. developwithwp/metabox-control

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

developwithwp/metabox-control
=============================

A Library which handles conditionally showing and hide metaboxes on a per template bases.

0342JavaScript

Since Oct 2Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mrbobbybryant/metabox-control)[ Packagist](https://packagist.org/packages/developwithwp/metabox-control)[ RSS](/packages/developwithwp-metabox-control/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Metabox Control
===============

[](#metabox-control)

**Table of Contents**

- [Introduction](#introduction)
- [Installation](#installation)
- [API Documentation](#api_documentation)
- [Usage](#usage)
- [Roadmap](#roadmap)

### Introduction

[](#introduction)

Metabox Control is a small Javascript API that allows you to take back control of your Page edit screen. One metabox at a time. Metabox Control allows you to **control** when metaboxes are rendered to the screen.

### Why?

[](#why)

Over time, it never fails. You create 2 or 3 custom page templates. You add 2 or 3 metaboxes to provide the end user an outstanding WordPress experience. And then **BAM**. Your perfectly laid plans become a cluttered mess.

### How

[](#how)

Metabox Control allows you to specify which metaboxes belong to which page template. And thats all you have to do. Wait until use see the Usage section. It is super minimal.

From there Metabox Control will handle the showing and hiding of your metaboxes. Which is based on the currently selected template from the page template dropdown. So lets look at some code.

Installation
------------

[](#installation)

Clone or download this repo to your WordPress project's plugin directory.

```
$ git clone https://github.com/mrbobbybryant/metabox-control.git
```

Once you have the code downloaded, simply activate the plugin just like normal.

API Documentation
-----------------

[](#api-documentation)

Metabox Control provides both a Javscript and a PHP API for registering Templates and their associted metaboxes.

\###Javascript

#### metaboxControl.addTemplate( templateName, array( metabox-ids ) );

[](#metaboxcontroladdtemplate-templatename-array-metabox-ids--)

> This method is used to register a page template and it's associated metaboxes.

- `templateName` - (string) - **required** - This is the php file name. For example, `page-template-one.php`
- `metabox-ids` - (array) - **required** - An array of all the metabox ids you wish to show and hide, depending on this page template. These IDs are the same ones used when registering a metabox. When registering a metabox, this will be the first parameter passed into `add_meta_box()`.
- **Returns** - New array -or- Error.

```
metaboxControl.addTemplate( templateName, array(metabox-ids));
```

#### metaboxControl.removeTemplate( templateName );

[](#metaboxcontrolremovetemplate-templatename-)

> This method will remove the given template from Metabox Control.

- `templateName` - (string) - **required** - This is the php file name. For example, `page-template-one.php`. This should correlate to a previously registered template.
- **Returns** - New array -or- Error.

```
metaboxControl.removeTemplate( templateName );
```

#### metaboxControl.getTemplates( ) );

[](#metaboxcontrolgettemplates--)

> This method does not except any parameters. It allows you to query Metabox Control and get a list of all templates that it is tracking. This can be useful for troubleshooting.

- **Returns** - The `registeredTemplates` array which is encapsulated within Metabox Control.

```
metaboxControl.getTemplates();
```

#### metaboxControl.getTemplates( ) );

[](#metaboxcontrolgettemplates---1)

> This method does not except any parameters. It is simply a helper function for quickly see which WordPress page template is currently selected.

- **Returns** - The currently selected WordPress page template.

```
metaboxControl.currentTemplate();;
```

API Documentation( Continued )
------------------------------

[](#api-documentation-continued-)

\###PHP The PHP code has been namespaced. The Public API uses the namespace `metabox_control\API;`.

#### add\_metabox\_template( $template, $metaboxes );

[](#add_metabox_template-template-metaboxes-)

> This method is used to register a page template and it's associated metaboxes. It will also check if the request template has already been registered. If so it will call `update\_metabox\_templates``` internally.

- `template` - (string) - **required** - This is the php file name. For example, `page-template-one.php`
- `metaboxes` - (array) - **required** - An array of all the metabox ids you wish to show and hide, depending on this page template. These IDs are the same ones used when registering a metabox. When registering a metabox, this will be the first parameter passed into `add_meta_box()`.
- **Returns** - Boolean -or- Exception.

```
\metabox_control\API\add_metabox_template( 'page-two.php', array('mb_two') );
```

#### remove\_metabox\_template( $template );

[](#remove_metabox_template-template-)

> This method is used to remove a previously registers template

- `template` - (string) - **required** - This is the php file name. For example, `page-template-one.php`
- **Returns** - Boolean -or- Exception.

```
\metabox_control\API\remove_metabox_template( 'page-two.php' );
```

#### update\_metabox\_template( $metaboxes, $exists = null );

[](#update_metabox_template-metaboxes-exists--null-)

> This method is used to update a previously registers template.

- `template` - (string) - **required** - This is the php file name. For example, `page-template-one.php`
- `metaboxes` - (array) - **required** - This is an array of metabox id.
- ``exists`- (bool) - **optional** - This argument is used internally by`add\_metabox\_template()``` when it determines a template has already been entered.
- **Returns** - Boolean -or- Exception.

```
\metabox_control\API\remove_metabox_template( 'page-two.php', array('mb_two') );
```

Usage
-----

[](#usage)

In the example below I will be simiulating the adding of two page templates in Javascript ( **page-one.php** and **page-two.php** ), as well as a few metabox( **mb\_one**, **mb\_three** and **mb\_two** ). Again these will depend on your implementation, and is simply an example.

```
metaboxControl.addTemplate( 'page-one.php', ['mb_one', 'mb_three']);
metaboxControl.addTemplate( 'page-two.php', ['mb_two']);
```

That's it! Now when you go to Create or Edit a WordPress Page, those metaboxes will only be visible when you have selected the associated page template.

Roadmap
-------

[](#roadmap)

- Test Converage
- While already possible, I'd like to make it even easier to remove Default Metaboxes.
- Add Build Process to Minify
- Convert to ES6
- Host on Bower to better handle Dependencies.
- Improve DOM caching. Current Implementation could lead to redundant DOM Object being cached.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8323ec7131dbb68e4fd8afc49af920a501a932ad401cc2c08911241d39ef1dfc?d=identicon)[mrbobbybryant](/maintainers/mrbobbybryant)

---

Top Contributors

[![mrbobbybryant](https://avatars.githubusercontent.com/u/7875796?v=4)](https://github.com/mrbobbybryant "mrbobbybryant (5 commits)")

### Embed Badge

![Health badge](/badges/developwithwp-metabox-control/health.svg)

```
[![Health](https://phpackages.com/badges/developwithwp-metabox-control/health.svg)](https://phpackages.com/packages/developwithwp-metabox-control)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
