Last active
July 10, 2019 14:12
-
-
Save svandragt/dd32f014b9ebbabdbac8afc4b58b1e5b to your computer and use it in GitHub Desktop.
WordPress Theme Feature Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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