Skip to content

Instantly share code, notes, and snippets.

View likesalmon's full-sized avatar

Ammon Morris likesalmon

View GitHub Profile
@likesalmon
likesalmon / gist:6df53215a0f91cf4864a
Last active August 29, 2015 14:14
Add page slug to body_class() template variable in Wordpress themes. For use in /wp-content/themes/myTheme/functions.php.
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = 'slug-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );
@likesalmon
likesalmon / class_foundation_offcanvas_nav_menu.php
Created February 2, 2015 21:27
Add a "dropdown" class to the sub-nav ul element for Foundation off canvas nav menus. For use with the wp_nav_menu() Walker argument.
/*
Add a "dropdown" class to the sub-nav ul element for Foundation off canvas nav menus
*/
class Foundation_Offcanvas_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"right-submenu\">\n";
$output .= '<li class="back"><a href="#">Back</a></li>';
}
}
@likesalmon
likesalmon / add_slug_class_to_menu_item.php
Created February 2, 2015 21:31
Add slug to css classes in wp_nav_menu() menu items. For use in /wp-content/themes/myTheme/functions.php.
/**
* Add slugs to custom menu items
*/
function add_slug_class_to_menu_item($output){
$ps = get_option('permalink_structure');
if(!empty($ps)){
$idstr = preg_match_all('/<li id="menu-item-(\d+)/', $output, $matches);
foreach($matches[1] as $mid){
$id = get_post_meta($mid, '_menu_item_object_id', true);
$slug = basename(get_permalink($id));