Skip to content

Instantly share code, notes, and snippets.

@svandragt
Last active July 10, 2019 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svandragt/dd32f014b9ebbabdbac8afc4b58b1e5b to your computer and use it in GitHub Desktop.
Save svandragt/dd32f014b9ebbabdbac8afc4b58b1e5b to your computer and use it in GitHub Desktop.
WordPress Theme Feature Setup
<?php
// mu-plugins/theme-features.php
require_once( FEATURES_DIR . '/myfeature.php' );
// mu-plugins/theme-features/myfeature.php
function features_myfeature_init() {
if ( current_theme_supports( 'myfeature' ) ) {
add_action( 'some_hook', 'features_myfeature' );
}
}
add_action( 'wp_loaded', 'features_myfeature_init' );
function features_myfeature() {
$defaults = [ 'type' => 'foobar'];
$options = (array) get_theme_support( 'myfeature' );
$options = wp_parse_args( $options, $defaults);
// do stuff
echo ($options['type']); // qwerty
}
// theme/functions.php
function mytheme_setup() {
add_theme_support( 'myfeature', ['type' => 'qwerty'] );
}
add_action( 'after_setup_theme', 'mytheme_setup' );
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment