Last active
January 11, 2016 16:39
-
-
Save yumyo/143c0159c5bfde6ab342 to your computer and use it in GitHub Desktop.
WordPress FEATURE BASED ROUTING - Example based on Sage but could be extended / adapted to any WP or HTML theme
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
<body <?php body_class(); ?> data-features="<?php echo Roots\Sage\Extras\get_feature(); ?>"> |
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
function get_feature() { | |
if (is_single()) { | |
$feature = 'feature_one'; | |
} elseif(is_page() && !is_front_page()) { | |
$feature = 'feature_two'; | |
} elseif(is_front_page()) { | |
$feature = 'feature_three'; | |
} else { | |
$feature = ''; | |
} | |
return $feature; | |
} | |
add_action( 'wp_head', __NAMESPACE__ . '\\get_feature' ); |
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
SITE = {}; | |
var body = document.body; | |
SITE.features = { | |
init: function() { | |
var features = body.getAttribute( "data-features" ); | |
var featuresArray = []; | |
this.common.init(); | |
if(features) { | |
featuresArray = features.split(' '); | |
for(var x = 0, length = featuresArray.length; x < length; x++) { | |
var func = featuresArray[x]; | |
if(this[func] && typeof this[func].init === 'function') { | |
this[func].init(); | |
} | |
} | |
} | |
}, | |
common: { | |
init: function() { | |
} | |
}, | |
feature_one: { | |
init: function() { | |
} | |
}, | |
feature_two: { | |
init: function() { | |
} | |
}; | |
SITE.features.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment