Last active
July 27, 2018 11:32
-
-
Save joshuadavidnelson/55f4c28748ce6b5853b2 to your computer and use it in GitHub Desktop.
Create custom theme features with theme feature support
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 | |
/** | |
* Basic Theme Support usage. Add this to your functions.php file | |
*/ | |
add_theme_support( 'custom-footer-text' ); | |
/** | |
* Elsewhere in your theme... | |
*/ | |
if( current_theme_supports( 'custom-footer-text' ) ) { | |
echo 'Custom Footer Text!'; | |
} |
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 | |
/** | |
* Determines, whether the specific theme feature is actually supported. Place this in your plugin file. | |
* | |
* @link https://github.com/zamoose/themehookalliance/blob/master/tha-theme-hooks.php | |
* | |
* @param bool $bool true | |
* @param array $args The hook type being checked | |
* @param array $registered All registered hook types | |
* | |
* @return bool | |
*/ | |
if( ! function_exists( 'jdn_toolkit_current_theme_supports' ) ) { | |
function jdn_toolkit_current_theme_supports( $bool, $args, $registered ) { | |
if( isset( $args[0] ) && isset( $registered[0] ) ) { | |
return in_array( $args[0], $registered[0] ); | |
} else { | |
return false; | |
} | |
} | |
} | |
add_filter( 'current_theme_supports-jdn-toolkit', 'jdn_toolkit_current_theme_supports', 10, 3 ); |
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 | |
/** | |
* Checks a theme's support for a given feature before loading the functions which implement it. | |
* | |
* @param string $feature The feature being checked. | |
* @param string $include Path to the file. | |
* @return bool True if the current theme supports the supplied feature, false otherwise. | |
*/ | |
if( !function_exists( 'require_if_jdn_toolkit_supports' ) ) { | |
function require_if_jdn_toolkit_supports( $feature, $include ) { | |
if( current_theme_supports( 'jdn-toolkit', $feature ) ) { | |
require ( $include ); | |
return true; | |
} | |
return false; | |
} | |
} | |
/** | |
* Usage | |
*/ | |
require_if_jdn_toolkit_supports( 'theme-options', 'path/to/file.php' ); |
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 | |
/** | |
* Add theme support to your function.php file | |
*/ | |
add_theme_support( 'jdn-toolkit', array( 'theme-options', 'portfolio', 'custom-footer-text' ) ); | |
/** | |
* Elsewhere in your theme... | |
*/ | |
if( current_theme_supports( 'jdn-toolkit', 'custom-footer-text' ) { | |
echo 'Custom Footer Text!'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment